如何使用 F# Interactive 交互测试 C# 函数
我有一组静态实用方法,包括单元测试。但我希望有一种更具交互性的方式来进行测试 ->固定->编译周期(REPL)就像 Lisp 或 Smalltalk 中的那样,可以在交互模式下立即执行代码。我尝试使用 F# Interactive 直接从 VS 2010 中打开的 C# 项目中测试这些方法,但没有成功。
我知道我必须加载程序集(#r
指令),打开命名空间,然后可以调用方法(并检查结果)。但是如何在 Visual Studio 2010 的“F# Interactive”中执行此操作呢?我知道可以在调试模式下使用“立即”窗口,但当我编写代码时,我想在“设计模式”下的 F# Interactive 中执行此操作。
I have a set of static utility methods including unit tests. But I'd like to have a more interactive way to employ a testing -> fixing -> compiling cycle (REPL) like in Lisp or Smalltalk where one can immediately execute code in interactive mode. I tried to use F# Interactive to test these methods directly from within the opened C# project in VS 2010, but I didn't get it to work.
I know that I have to load the assembly (#r
directive), open the namespace and then can call the methods (and inspect the result). But how do I do it within “F# Interactive” in Visual Studio 2010? I know it is possible with the “Immediate” window available in debug mode, but I want to do it within F# Interactive in "design mode", when I'm writing the code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用
#I
指令包含项目的路径,然后您可以加载程序集并使用它。我编写了一个简单的 C# 控制台应用程序,尝试一下并使其正常工作。然后在 F# 交互式中:
所以它肯定有效,您只需要先编译您的项目即可。只需记住重置会话以提前释放程序集即可。
You need to include the path to your project using the
#I
directive then you may load your assembly and use it. I wrote a simple C# console app try this and got this to work.Then in F# interactive:
So it definitely works, you just need to compile your projects first. Just remember to reset your session to release your assembly beforehand.