如何在 Visual Studio 2008 中对 F# 代码进行单元测试?

发布于 2024-07-12 22:43:18 字数 302 浏览 5 评论 0 原文

我是 F# 新手,打算创建新的 F# 项目,并在 Visual Studio 2008 中使用 F# 对其进行单元测试,但 Visual Studio 2008 单元测试向导没有 F# 测试项目选项(只有 C、C# 和VB 选项)。

  1. 是否可以对 F# 进行单元测试?
  2. 是否可以使用 F# 测试项目对 F# 进行单元测试?
  3. 是否可以在 Visual Studio 2008 中使用 F# 测试项目对 F# 进行单元测试?
  4. 如果Visual Studio 2008中没有向导怎么办?

I'm new to F# and I intend to create new F# project, and unit test it with F# in Visual Studio 2008, but the Visual Studio 2008 Unit Test Wizard don't have a F# test project option (just have C, C# and VB options).

  1. Is it possible to unit test F#?
  2. Is it possible to unit test F# with a F# test project?
  3. Is it possible to unit test F# with a F# test project in Visual Studio 2008?
  4. How to do it, if there is no Wizard in Visual Studio 2008?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

陪我终i 2024-07-19 22:43:18

此链接介绍了如何使用 VS 测试系统和 F# 。 您的操作方式与 C# 几乎相同。

缺点是 VS IDE 显然不会自动选择它——我相信您需要使用 mstest.exe

编辑:哦,F# 的另一个很酷的东西是 FsCheck。 这允许您编写简单的测试,并让 FsCheck 系统尝试通过随机测试来反驳它们。

This link describes using the VS testing system with F#. You do it pretty much the same way as with C#.

The downside is that apparently the VS IDE won't automatically pick it up -- I believe you need to run from the command line using mstest.exe.

Edit: Oh, another cool thing with F#, is FsCheck. This allows you to write simple tests, and have the FsCheck system try to disprove them via random testing.

指尖微凉心微凉 2024-07-19 22:43:18

我找到了这篇关于使用 nunit 进行 f# 测试的文章(链接此处)。 不过,我确实记得还有另一种方法来验证函数式语言代码的有效性(我使用 Clean 进行工作,这与我的学士学位的 Haskell 类似)。 只是记不清他们到底叫什么了,我记得它更像是一个数学证明。
另外,我不确定它是否适用于 F#,因为如果我没读错的话,它与 Haskell 风格的语言有点不同。

I found this article on f# testing with nunit (link here). I do remember however that there's another way to verify the validity of functional language code (I 'worked' with Clean, which is similar to Haskell for my bachelor). Just can't remember exactly what they called it, I do remember it's more like a mathematical proof.
Also, I'm not sure that it works for F#, as it's a bit different from Haskell'esque languages if I read that correctly.

不及他 2024-07-19 22:43:18
  1. 如果您正在生成 .NET 代码,则可以使用 nunit 对 F# 进行单元测试,只要接口相当符合 CLI 规范。
  2. Nunit 使用 .NET 程序集,而不是任何特定语言。 如果您可以在类上删除 [TestFixture] 属性,并且可以在特定类中的公共方法(返回 void)上删除 [Test] 属性,则 NUnit 可以运行它。
  3. 不知道。
  4. 不知道。
  1. If you're generating .NET code, it is possible to unit test F# with nunit, as long as the interface is reasonably CLI compliant.
  2. Nunit works with .NET assemblies, not with any particular language. If you can drop the [TestFixture] attribute on a class and can drop the [Test] attribute on a public method in a particular class, which returns void, then NUnit can run it.
  3. Don't know.
  4. Don't know.
绅士风度i 2024-07-19 22:43:18

没有什么强迫您使用 F# 来测试 F#。 您可以简单地使用 C#、VB 或其他 .NET 支持的语言创建单元测试程序集,并简单地引用执行测试所需的 F# 程序集。 您将像为任何其他 .NET 程序集创建单元测试一样执行此操作。

There's nothing forcing you to use F# to test F#. You could simply create a unit test assembly in C#, VB or another .NET supported language, and simply reference the F# assembly needed to perform the tests. You would do it just as you would create unit tests for any other .NET assembly.

恋你朝朝暮暮 2024-07-19 22:43:18

我不确定这是否与您的确切问题严格相关,但 Matthew Podwysocki 的博客上有一系列关于函数式语言单元测试的帖子 - 那里也有一些 F# 位。

I'm not sure whether this is strictly related to your exact question, but there are a whole series of posts on Matthew Podwysocki's blog about unit testing in functional languages - there are some F# bits in there too.

  • Part 1 - xUnit Frameworks - HUnit
  • Part 2 - Property-Based Tests - QuickCheck
  • Part 3 - QuickCheck + xUnit Tests Together
  • Part 4 - Code Coverage
  • Part 5 – Keeping Things Pure
  • Part 6 – Monadic Abstractions
  • Aside – Using Type Classes
  • Part 7 - Improving Your Codebase
娜些时光,永不杰束 2024-07-19 22:43:18

您是在问是否可以在 F# 中进行单元测试,还是在询问是否有一个向导? 可以用任何语言进行单元测试,事实上,函数式语言是单元测试人员的梦魇(我听说它是​​这样描述的),因为一切都是静态的,并且您已经验证了所有边缘情况,您基本上已经验证了每种情况。

编辑:要回答第四个问题,请编写自己的测试用例:

http://en.wikipedia.org/维基/单元测试

Are you asking if it's possible to unit test in F# or are you asking if there's a wizard for it? It's possible to unit test in any language, in fact, functional languages are a unit testers wet dream (I heard it described that way.) since everything is static and you've verified all the edge cases you've essentially verified every case.

EDIT: To answer the fourth question, write your own test cases:

http://en.wikipedia.org/wiki/Unit_testing

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文