views:

155

answers:

9

We are using Asp.Net 2.0 and planning to move to TDD so that middle tier can be developed and tested while others in the team take care of UI and DataBase area.

Can anyone kindly let me know the pre-requisites for TDD and which one is the best tool for .net? Thanks...

[UPDATE]

Thanks everyone for your answers and help.

  • I was reading an article about TDD and ASP.NET and it said "ASP.NET is not very TDD-friendly and ASP.NET MVC framework is alternative way to build your application which is more testable than form=based application." Should I switch/change to ASP.NET MVC?

  • What book(s) do you recommend about TDD /Test?

A: 

Don't know the best, but I like NUnit.

x2
+3  A: 

Hi there,

NUnit is the most widely used. but there are many others out there also like XUnit and Machine.Specification for BDD style testing.

Which you choose depends on the type of testing you wish to do.

Blounty
+1  A: 

TestDriven.NET is a great addin for Visual Studio that makes running tests within your solutions painless. I have had success with both MbUnit and NUnit along with something like Rhino.Mocks or Moq so that you can create mock objects within your tests.

zac
A: 

While NUnit has been around for some time and is definitely the incumbent, I prefer XUnit.NET by far. It is a very modern, forward-looking framework that completely changes the unit testing game. Unlike previous testing frameworks, XUnit.NET is extensible, allowing you (or a third party) to change the way the framework behaves, allowing a wide variety of approaches to testing such as BDD style "specifications".

There are quite a few XUnit.NET "morphing" frameworks that offer a variety of different approaches to implementing BDD. I won't list them all...I'll just list the one I use myself. It is simple, strait forward, and extremely easy to use: SubSpec. Created by Phil Haack, a Microsoft program manager, its probably the easiest way to break into BDD style testing.

In addition to XUnit.NET, I also recommend Moq as the mocking framework of choice. Like XUnit.NET, Moq is a very modern, forward-looking framework that changes the mocking game, and has pioneered newer things like lambda expressions, eliminating record/replay semantics, etc.

jrista
+3  A: 

Unit testing & mocking

I suggest you combine NUnit and Moq for object mocking. It will take more effort from you to do unit testing in a web forms application though.

  • NUnit is well established, alive project and widespread.
  • Moq on the other hand uses latest language capabilities, is easy to use and is also used by the community.

The thing is, you can't miss with these two.

Switch to MVC if early in the project

If you're in an early stage of the project I suggest you do switch to Asp.net MVC, because it will make your life lots easier with unit testing. But beware of the learning curve here, because MVC is not just a superset on Asp.net Web forms. It's a completely different paradigm and development platform. But I doubt you'll regret switching to it.

Robert Koritnik
I think i'll switch to MVC, which it make sense to me while i have control over my HTML, beside testing. I agree with you, MVC is not like web forms while everything is in code behind. But it worth it.Do you recommend very good resource or any open source project to lean from it?
egyamado
Yes. Try with NerdDinner. It's a nice learn-by-example project. http://www.asp.net/mvc/learn/
Robert Koritnik
+1  A: 

Regarding books, I recommend The Art of Unit Testing, by Roy Osherove. It's not ASP.NET specific, but it covers both the bases of unit testing, as well as guidance on how to develop a test suite that will remain maintainable over time. Lots of good stuff on Mocking, too.
alt text

Mathias
+1  A: 

There are bunch of testing/mocking frameworks whose perfectly works everywhere except ASP.NET related stuff. If you are planing to move from pure ASP.NET to something testable you anyway will be required to use one of wellknown patterns to separate views from business layer. So most probably you will deal with MVC, MVP or MVVM approach.

Asp.net MVC is a good option but, as it was mentioned here, it brings new programming paradigm and some restrictions like inability to use old ASP.NET controls. And of course there are cases when such restrictions are unacceptable.

When we met the similar problems is more than two years ago we've not found good solution which would allow us at least to hold an ability to use any UI controls we want but at the same time to have as much as possible testable code. We decided to build something usable by our own...

This spring we extracted results of our efforts into separate project and published. We called this new framework LiveUI. Please take a look. Probably it will satisfy your needs.

Alex Ustinov
A: 

While most people here have talked about unit testing (and don't get me wrong that is very very important). You should also be doing integration/functional testing particularly around exorcising the client requirements. For this I highly recommend Fitnesse. This is a testing framework that sits just under your UI and provides a alternative UI for accessing your business logic. I find it to be invaluable.

ryber
A: 

Pragmatic Unit Testing in C# with NUnit is a good book to get you started with using NUnit and it also covers mocking.

Also, ASP.NET MVC in Action can get you started with ASP.NET MVC and as well as show you how to unit test your controller code.

jamesaharvey