views:

11113

answers:

9

There are quite a lot of unittesting frameworks out there for .NET. I found this little feature comparison: http://www.codeplex.com/xunit/Wiki/View.aspx?title=Comparisons

Now I am to choose the best one for us. But how? Does it matter? Which one is most future proof and has a decent momentum behind it? Should I care about the features? While xUnit seems to be most modern and specifically designed for .NET, nUnit again seems to be the one that is widely accepted. MSTest again is already integrated into Visual Studio ...

+37  A: 

NUnit is probably the most supported by the 3rd party tools. It's also been around longer than the other three.

I personally don't care much about unit test frameworks, mocking libraries are IMHO much more important (and lock you in much more). Just pick one and stick with it.

Alexander Kojevnikov
what is your top mock library pick?
dplante
I like Moq, RhinoMocks is also good.
Alexander Kojevnikov
It might also be worthwhile to check Pex and Moles, the moles part especially is useful for mocking.
Charles Prakash Dasari
+3  A: 

It's not a big deal, it's pretty easy to switch between them. MSTest being integrated isn't a big deal either, just grab testdriven.net.

Like the previous person said pick a mocking framework, my favourite at the moment is Moq.

+32  A: 

I wouldn't go with MSTest. Although it's probably the most future proof of the frameworks with Microsoft behind it's not the most flexible solution. It won't run stand alone without some hacks. So running it on a build server other than TFS without installing Visual Studio is hard. The visual studio test-runner is actually slower than Testdriven.Net + any of the other frameworks. And because the releases of this framework are tied to releases of Visual Studio there are less updates and if you have to work with an older VS you're tied to an older MSTest.

I don't think it matters a lot which of the other frameworks you use. It's really easy to switch from one to another.

I personally use XUnit.Net or NUnit depending on the preference of my coworkers. NUnit is the most standard. XUnit.Net is the leanest framework.

Mendelt
I've been dragged kicking and screaming to this same conclusion. I really wanted to use MSTest because of it's integration with Visual Studio, but that's also its weakness. I need to run tests on a non-Microsoft build server and there aint no way I am installing Visual Studio on it just to get that. It's a shame that Microsoft produces great tools and then renders them almost unattainable.
Tim Long
+5  A: 

It's not a big deal on a small/personal scale, but it can become a bigger deal quickly on a larger scale. My employer is a large Microsoft shop, but won't/can't buy into Team System/TFS for a number of reasons. We currently use Subversion + Orcas + MBUnit + TestDriven.NET and it works well, but getting TD.NET was a huge hassle. The version sensitivity of MBUnit + TestDriven.NET is also a big hassle, and having one additional commercial thing (TD.NET) for legal to review and procurement to handle and manage, isn't trivial. My company, like a lot of companies, are fat and happy with a MSDN Subscription model, and it's just not used to handling one off procurements for hundreds of developers. In other words, the fully integrated MS offer, while definitely not always best-of-bread, is a significant value-add in my opinion.

I think we'll stay with our current step because it works and we've already gotten over the hump organizationally, but I sure do wish MS had a compelling offering in this space so we could consolidate and simplify our dev stack a bit.

ReSharper does have a compelling offering in this space!
Squirrel
+34  A: 

I know this is an old thread, but I thought I'd post a vote for xUnit.NET. While most of the other testing frameworks mentioned are all pretty much the same, xUnit.NET has taken a pretty unique, modern, and flexible approach to unit testing. It changes termonilogy, so you no longer do you define TestFixtures and Tests...you specify Facts and Theories about your code, which integrates better with the concept of what a test is from a TDD/BDD perspective.

xUnit.NET is also EXTREMELY extensible. Its FactAttribute and TraitAttribute attribute classes are not sealed, and provide overridable base methods that give you a lot of control over how the methods those attributes decorate should be executed. While xUnit.NET in its default form allows you to write test classes that are similar to NUnit test fixtures with their test methods, you are not confined to this form of unit testing at all. You are free to extend the framework to support BDD-style Concern/Context/Observation specifications, as depicted here.

xUnit.NET also supports fit-style testing directly out of the box with its Theory attribute and corresponding data attributes. Fit input data may be loaded from excel, database, or even a custom data source such as a Word document (by extending the base data attribute.) This allows you to capitalize on a single testing platform for both unit tests and integration tests, which can be huge in reducing product dependencies and required training.

Other approaches to testing may also be implemented with xUnit.NET...the possabilities are pretty limitless. Combined with another very forward looking mocking framework, Moq, the two create a very flexible, extensible, and powerful platform for implementing automated testing.

jrista
+1  A: 

Nunit doesnt work well with mixed-mode projects in C++ so I had to drop it

Eric
+9  A: 

I personally don't like xUnit.Net because its adoption of a confusing naming scheme such as "Fact", "Theory" etc, instead of the common jargon. There are numerous examples of such (the chart shows them).

Besides the confusion, it makes migration from one framework to another a Replace All hassle. I really wonder which fundamental problem they have addressed with those changes.

ssg
Based on the downvotes without comments, we can also add that xUnit.net has built up a fanboy community who lack proper articulation and rebuttal skills.
ssg
I can assure you they're not testkiddies that want to dream up new names for stuff. Have a play with it - I dismissed it for far too long and love it now. And go easy on the drivebyt -1ers!
Ruben Bartelink
Didn't think of driveby downvoters, good point, I take my hasty statement back. However I could find no sane reason for such naming change, except that it sounded so radical and revolutionary but in fact had no tangible benefit. I'm afraid that perspective might be crept in the overall project so I'll keep myself in safe havens of NUnit unless it's proven that xUnit.net doubles the productivity.
ssg
Given xUnit.NET's flexibility, it is a trivial matter to extend the Fact attribute to create a Test attribute that functions the same way. If your beef is with having to search-and-replace...your approaching the problem the wrong way. xUnit.NET solves a lot of problems, not simply because it is a different framework...but because it is an extensible framework that allows YOU to figure out how to provide solutions to testing problems. See my answer above for more.
jrista
@jrista I'm not saying xUnit.NET isn't flexible. I'm saying that a test is not a fact but a piece of code. And a bunch of tests do not make a theory either. This kind of naming is at least stupid, and has no justification. If someone went this far in absurdity, they might as well have done other smelly stuff. Besides the frustration it causes, I regard this as a bad sign. That's all I'm saying. There is even a document titled "Running a theory" for God's sake. And you mention flexibility. Here is my theory, run it now.
ssg
I think it depends on how you look at it. Your only viewing testing from the narrow perspective of that the ?Unit frameworks defined. That is not the only way to view your test suites. In my world, I approach tests from the BDD perspective, wherin tests ARE facts about my code...verifiable facts: "Given context [x] and [y], when [operation] then [fact] is true." Also, I think you entirely misunderstand the concept of theories. Theories are not "a bunch of tests"...theories are parameterized tests that make use of a data source to provide a variety of input data. You could...
jrista
...write 50 similar tests, and explicitly provide different input data to each. Or, you could write a Theory, populate an Excel worksheet with a variety of data that test critical input cases, and bind that worksheet to your Theory. Theories are a far more efficient and effective way of testing units that must function across a broad range of input data. Theories are also very similar to the FIT style of testing, such as Fitnesse, which uses HTML tables in a Wiki to do the same exact thing. I think you should open your mind to the wide varieties and approaches to testing and BENEFIT from them.
jrista
No, that's the excuse you'd hear from it's creator: "Hey we thought about BDD, that's why". But if they really had their mind wrapped around BDD concept, we wouldn't see "Assert"s. Instead we would see such an elegant, perfectly designed framework which would have "EnsuresThat", "RequiresThat", "ButNeverDoesThat" kind of constructs; something like code contracts. And I'm saying it, this is an half-assed solution to a problem that never existed (BDD'ers have no problem with NUnit/JUnit conventions). And this IS A BAD DESIGN which IS A BAD SIGN for the future of xUnit.NET.
ssg
@SSG: Sad to see you aren't willing to look past the limited vision that ?Unit frameworks have to offer, and see the doors that xUnit.NET opens. You suggestion about a "perfectly designed" framework using "EnsuresThat", "RequiresThat", etc. IS available, along with various BDD extensions on top of xUnit.NET, in the xUnit.NET contributions project.
jrista
The guy with limited vision is the king in the world of blind, jrista. I wish you a very happy life with xUnit.NET :)
ssg
A: 

Eric, what you used instead of nUnit. I have a mixed-mode project too

Omar
A: 

Since we have some experience with both MBUnit v3 and NUnit 2.5.x now, I can compare both:

  • We found MBUnit less stable than NUnit. Sometimes MBUnit processes don't shut down and prevent CC.Net from cleaning up test folders, causing faux failures.
  • Both are equally easy to use for writing unit tests. Semantics are almost intact.
  • MBUnit client Gallio Icarus is too slow and sluggish. Example: Its startup time is 30 seconds on my quad core, RAID, 4gb machine, before loading tests. (EDIT: This turned out to be a bug with Gallio which can be worked around by removing all permissions from Gallio.Utility.exe)
  • MBUnit test run times on GUI client are much longer than NUnit GUI client. In overall, the GUI client looks bloated.
  • Console clients have similar execution times.
  • MBUnit supports parallelization of tests though, which can compensate for slow GUI-client execution but that requires manual tuning.
  • MBUnit does not support NUnit's Assert.That(output, Is.Condition(expectedValue)) syntax, which makes migration from NUnuit harder if you're used to it (because expectedValue and output needs to be swapped).
  • Debugging MBUnit tests is easier because of client's VS integration support.
ssg