简体   繁体   中英

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?

Here's a scenario:

  1. You're in a team where all developers are C# 2.0-only, slowly learning about LINQ and lambdas.

  2. They don't cover a single line with unit tests, which would place unit tests in F# at rarefied heights.

  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#.

The fact that unit test snippets can easily be executed in F# Interactive is another possible advantage of testing with 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.

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. ( for example you don't have to Pascal the test name. It can be a normal sentence. )

But like Brian says, in your case, you are better off starting with C# for the unit tests and then see how things go.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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