Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which Unit Test framework should I start with for C# in Visual Studio 2008? (Windows Forms app)

QUESTION - If I'm starting a Windows Forms application in C# using Visual Studio 2008, which unit testing framework should I use?

There seems to be one build into VS2008? Or should I look into something like NUnit? Or is NUnit what is used in VS2008 under the bonnet? What's the most popular.

Would be good to have something that allows for: (a) mocking/stubs, and (b) ability to assert exceptions

thanks

like image 879
Greg Avatar asked Oct 08 '09 01:10

Greg


2 Answers

I would recommend using NUnit for your testing framework. It's very lightweight and easy to ship around if you need to get it set up on a build server. This isn't the case using MSTest. As for mocking/isolation frameworks, Rhino Mocks has the largest user base and you're likely to find answers to your questions quickest with Rhino Mocks.

like image 164
Chris Missal Avatar answered Nov 15 '22 19:11

Chris Missal


If it just a simple application, the MSTest framework built into VS2008 should tick all the boxes. It is not the same as NUnit, though a lot of people (mistakenly) refer to it as if they were the same thing.

I have never used it for mocking, so maybe someone else can elaborate on that. It generates a separate project in your solution that is just for the purpose of testing. This is a good explanation of how to use it.

alt text
(source: geekzone.co.nz)

Edit: Doing a bit more digging, I came across this comparison of MSTest and NUnit.

Drawbacks of NUnit Framework:

  • Installation of NUnit comes in a separate MSI.
  • No Integration with Visual Studio.
  • Requires writing test cases manually.
  • No auto generation of code.
  • Requires opening separate window (NUnit Console or GUI) to execute test cases.
  • Ordering of test cases execution not available.
  • No inbuilt feature to debug test cases.
  • No inbuilt feature to enable/disable test cases.
  • No inbuilt feature to give additional information of test cases like stack trace, Trace Information etc.
  • No inbuilt feature to sort test cases based on Computer Name, Class Name and Host Type etc.

That's from the comparison article I linked to.

I have never used NUnit, only MSTest for C# and JUnit for Java, so I am kind of biased in that respect. MSTest has always worked really well for me for WinForms, with features like being able to run the tests individually, show really detailed reports (with individual trace logs) and autogenerate all the boilerplate test code and do all those kind of things that make VS2008 such a brilliant IDE. By the sounds of it, NUnit has worked well for others and they have their reasons why they like it.

Unless you have a particular reason to take the NUnit/Testdriven.NET approach, like you need a certain feature, or you just prefer that way of setting up tests and trying to integrate it back into VS, then I don't see any reason not to just use MSTest which works right out of the box.

like image 20
Dale Avatar answered Nov 15 '22 17:11

Dale