Since I don't have the time or the inclination to write one massive blog posting evaluating
all the alternative approaches and tools for test driven development, I have decided
to break this topic into several small posts. What I'm trying to get to is practical
examples of how one might use the free frameworks to enable a test first approach
to development. To get the ball rolling, I think the starting point must be
the .Net unit testing frameworks out there:
-
nUnit - This one needs no introduction.
It is the correct de facto standard for unit testing in .Net. There are several
projects that expand this framework, such as:
-
nUnitAsp - We've used this in several
projects, but at the end of the day it ended up being a good way to smoke test our
pages because of the effort required to write the scripts. This project really
needs a recorder.
-
nUnitForms - A windows forms UI testing
framework with a recorder.
-
nUnitX -
Uses attributes to extend nUnit (and MbUnit) to allow for seamless database rollbacks.
-
mbUnit -
This framework allows for the nesting of tests and supports data driven testing.
Some interesting comments and regarding nUnit and MbUnit can be found at this
blog posting. Another two articles/postings you may want to read are: MbUnit:
Generative Unit Test Framework or the abbreviated version at Understanding
MbUnit Architecture.
-
csUnit - Why bother really. This
is not a mainstream unit testing framework and it doesn't seem to offer any advantages
over any of the others. They claim that they offer different features to the
other unit testing frameworks, but don't bother to tell us what those are. In
general nUnit is better supported by a variety of other tools.
-
nMock - Allows one to isolate testing by
creating dummy (or mock) objects. You could then use this stub as a reference
object on the class that you are trying to test. Say a WorkQueue relied
on a UserProfile object when returning a list of work queues. You would want
to set the UserProfile up as a mock object to isolate the WorkQueue logic and check
that the calls going to UserProfile from WorkQueue.
-
DotNetMock -
Can't really see what it offers that is different from nMock. I have not downloaded
the code to check it out though.
-
EasyMock.Net - A port of
the Java EasyMock framework.
-
RhinoMock - From the
site: "Rhino.Mocks is an attempt to create easier way to build and use mock objects
and allow better refactoring support from the current tools. It's a hybrid approach
between the pure Record/Replay of EasyMock.Net's model and NMock's expectation based
model. Rhino.Mocks originated from EasyMock.Net and attempt to improve on their model
to create easy to use and power mocking framework."
-
TypeMock - Allows you to mock any concrete
class without refactoring your code and contains an expectation recording facility.
The standard edition is free.
-
Fitnesse - Allows you to take User Acceptance Tests
to the next level by having a wiki where tables can be used to drive tests and expected
results
A good related source of information is on Model
Based Testing. This site has a ton of white papers that I must start reading
at some point. A related CodeProject posting about developing a Production
Grammar Framework is also worth skimming.
The next posting will look at some Test
First Guidelines from experts and then on to practical implementation of all of
the above (taking some ideas from the CodeProject article Test-Driven
Development in .Net)
I asked a friend of mine from the UK, Grant Drake, to give me his thoughts on test
driven development and he decided to respond to my post with a posting of
his own. It really is a good read.