In this book, were testing with NUnit, a .NET testing framework written by Jim Newkirk, Michael Two, Alexei Vorontsov, and Charlie Poole, based on the original NUnit by Philip Craig. You can find it at . NUnit is much the same as all the Extreme Programming test frameworks (xUnits), with two important differences:

  1. NUnit uses the attribute feature of .NET to identify tests. As youll see, test fixtures are identified by the attribute [TestFixture] and individual tests by [Test]. This means that you can write tests that dont inherit from a fixed TestCase superclass and NUnit can still find them. At first I thought this was just gratuitously different, but Im finding that it works just fine and I rather like it.

  2. NUnit allows you to write tests in any .NET language. So even though NUnit itself is written in C#, you can write your tests in Microsoft Visual Basic or C++ or, I suppose, even in ML or Eiffel. Language interoperation is a key characteristic of .NET and one that I consider to be quite important.

When you write tests using NUnit, you can run the NUnit application and it will run and report on your tests. There are two versions of the app, one that runs at the command prompt and a GUI version. I prefer the GUI version and will be using it throughout most of this book. When I say NUnit, Im usually talking about that GUI, which looks like this:

click to expand

When you press the Run button, NUnit looks at your program, finds all the tests, and runs them. Each test fixture in your program has its own setup and teardown methods , and each test case runs with a fresh setup. This means that your tests are all automatically independent and that NUnit will run them all. If the tests all run correctly, NUnit displays a green bar, as just shown. (Trust me, the bar in the graphic above is green.) If any of the tests dont run, the bar is red.

Extreme Programming teams write lots of tests, and the rule is that we release code back to the repository only if all the tests run correctly. This may seem like a big burden , but it turns out not to be. And imagine how confident you can be in your code if you have lots of tests and every one of them is working correctly!

But enough warmup. Lets take a look at what its all about.

Extreme Programming Adventures in C#
Javaв„ў EE 5 Tutorial, The (3rd Edition)
ISBN: 735619492
EAN: 2147483647
Year: 2006
Pages: 291 © 2008-2017.
If you may any questions please contact us: