简体   繁体   English

使用基于F#的测试工具对C#实现进行单元测试

[英]Unit testing C# implementation with F#-based testing tools

Outside of things syntactical, are there scenarios where it would be advantageous to write unit tests using F# for Greenfield C# code? 在语法之外,是否存在使用F#为Greenfield C#代码编写单元测试的情况?

Here's a scenario: 这是一个场景:

  1. You're in a team where all developers are C# 2.0-only, slowly learning about LINQ and lambdas. 您所在的团队中所有开发人员都只使用C#2.0,慢慢了解LINQ和lambdas。

  2. They don't cover a single line with unit tests, which would place unit tests in F# at rarefied heights. 它们不包含单行测试,单元测试将F#中的单元测试放在稀薄的高度。

  3. Unit testing is a choice and responsibility of the developer who is creating code. 单元测试是创建代码的开发人员的选择和责任。

  4. If unit tests break, and the dev who wrote them is not on hand, the tests will be simply thrown away if they are hard to understand. 如果单元测试中断,并且编写它们的开发人员不在手边,那么如果难以理解,测试将被丢弃。

  5. Main requirement here is to create production code in C#. 这里的主要要求是用C#创建生产代码。

The fact that unit test snippets can easily be executed in F# Interactive is another possible advantage of testing with F#. 单元测试片段可以在F#Interactive中轻松执行,这是使用F#进行测试的另一个可能的优势。

That said, it sounds like for this particular scenario/organization, it might be enough work trying to get anyone to write/execute unit tests, so it may be better to just start with some C# unit tests and focus on getting the 'unit tests are good/useful' culture instilled first. 也就是说,听起来对于这个特定的场景/组织来说,尝试让任何人编写/执行单元测试可能已经足够了,所以最好从一些C#单元测试开始并专注于获得'单元测试先灌输好的/有用的文化。

I have found writing tests in FsUnit ( which is just a wrapper over nunit ) to be great and also the readability is good as well. 我发现在FsUnit中编写测试(这只是nunit的一个包装器)非常好,并且可读性也很好。 ( for example you don't have to Pascal the test name. It can be a normal sentence. ) (例如,您不必使用Pascal测试名称。它可以是正常的句子。)

But like Brian says, in your case, you are better off starting with C# for the unit tests and then see how things go. 但就像Brian说的那样,在你的情况下,你最好从C#开始进行单元测试,然后看看情况如何。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM