views:

1311

answers:

12

I'm looking to add a testing suite to my application, however I can't move to the newer testing frameworks for .NET 3.5. Does anyone have a suggestion about good testing frameworks to use?

A: 

NUnit is always a favorite of mine. However if you are using TFS as your source control I suggest you stick with the Microsoft Stack.

Nick Berardi
There are no compelling reasons to use MS Test over NUnit or MbUnit. It is flat out an inferior tool.
Ben Scheirman
Seconded. My recommendation is MbUnit.
Dmitri Nesteruk
That wasn't really my point with MS Test, there is a lot of nice surger that TFS gives you when combined with MS Test.
Nick Berardi
+2  A: 

For a Mock Object library, I've found the BSD-licensed Rhino.Mocks to be rather pleasing.

Rytmis
A: 

NUnit is available at http://www.nunit.org I would suggest this even when working on the MS stack - the support for non-MS frameworks is happening in the MVC previews which shows a definate movement in the right direction to allow us all to customise our stacks to fit.

Ronnie
+2  A: 

I've had great success using NUnit as well.

I've also used NMock when the need arose for mock objects. As an added bonus, the factory for creating your mock objects is called the Mockery.

To facilitate the running of unit tests, I've used TestDriven.NET to run unit tests as I coded. Also, I've used Cruise Control .NET to watch SVN and check that every new commit builds and passes all unit tests.

Jason Sparks
NMock's over use of magic strings makes it a poor choice for a mocking framework. RhinoMocks or Moq are better choices because they rely on strong typing.
Ben Scheirman
+2  A: 

We use MbUnit and Rihno Mocks and they prove to work very well together. When doing TDD you will almost certainly need to do some form of dependency injection, while this can be done manually, its worth looking at an IoC container such as Castle Windor.

It well worth looking at John Paul Bodhood's screen casts to get you started. JPB's Blog

Dan
A: 

Using nUnit with TFS isn't too difficult. There's even a project on codeplex to implement this: http://www.codeplex.com/nunit4teambuild which even "publishes" the results to the warehouse.

I haven't tried it - but I would advise clients who have a large investment (or who have a strong preference for it over the MSTest tool) in nUnit who are interested in implementing TFS to continue with nUnit as opposed to trying convert all their existing tests.

fuzzbone
+5  A: 

NUnit and Rhino suit well and the auto-mocking container might be of interest.

If you're looking at BDD too then NBehave is probably a good choice. If however you just mean the style of BDD that relates to unit testing (xSpec) though you can get away with adding a framework (though things like specunit do add some synctactic sugar), but you might want to look at MSpec is also interesting.

+1  A: 

I am going to have to put a shout out for Moq. It is clean light mocking framework that helps guide you into the pit of success.

The testing tools built into TFS are okay, they will get the job done but can often be a little cumbersome to work with. The generated reports, code coverage and a few other portions are particularly bad, they make you go bald at 22 rather than 50.

If you are really loving the testing, consider trying some Continuous Integration. You will feel the pain from regression quickly and potentially help you get to the end goal faster.

Regardless of what you do try out a few and see which one is the most natural, if you have time. Good luck and happy coding.

smaclell
The problem with Moq is that it require .NET 3.5 because it uses lambda expressions and expressions trees.
Michaël Larouche
Not necessarily a horrible thing but you are right, this would hold back a v2.0 shop.
smaclell
+2  A: 

This is probably a summary of what has already been said, but for TDD I personally use Rhino Mocks and MBUnit. Rhino Mocks is a mocking framework that is free and open source. The advantage of Rhino Mocks is we do not need to use magic strings in setting your expectations as you do in NMock.

I like MBUnit because MbUnit has the concept of RowTests which allow you to vary your inputs to your test method. MBUnit is also freely available.

You also want to make sure that whatever you choose for your unit testing framework is supported by your CI (Continuous Integration Server). Nunit is supported by default in Cruise Control.NET and you have to do a little extra work to get MBUnit to work in ccnet.

From an IDE standpoint you must have TestDriven.NET. TestDriven.NET allows you to right click and run tests in the IDE and it supports MBUnit and Nunit and others.

NBehave is the BDD library I have used. I have not used any others so I could not compare and contrast them with you, but NBehave is supported by Gallio from the MBUnit team, which means you can run your BDD tests just as you would your unit tests with TestDriven.NET.

I would also highly recommend Resharper. You will find your productivity increase significantly with this refactoring and guidence tool. It will assist you with changing your code as you are developing your tests.

Hope this helps

Michael Mann
A: 

I recommend the following:

TestDriven.NET - Unit Testing add on for VS that is fully integrated with all major unit testing frameworks including NUnit, MbUnit etc...

Typemock Isolator- A mocking framework for .Net Unit Testing

NUnit - An open source unit testing framework that is in C#.

+3  A: 

Check out Rob Conery's screencast on BDD using MSpec. Very impressive http://blog.wekeroad.com/mvc-storefront/kona-3/

mcintyre321
A: 

For my project, I used NUnit and TestDrived.NET with great success. You can either create a separate library just to host your test code or you can put it in your executable or library. It all depend if you want your production code to be intertwine with your test code.

For Depencendy Injection, I use NInject in my current project and its work great. If you use Constructor injection, you don't need to clutter your code with the [Inject] attribute.

I haven't used a mock library for my .NET 2.0 project but for another .NET 3.5 project I will use Moq

Note that all this works with .NET 2.0 and higher. (except Moq)

Michaël Larouche