2.4. Unit Testing Frameworks

The .NET Framework is lucky enough to have a vast number of excellent unit testing frameworks to support you when writing tests. Each framework has a different approach, targeting a different set of users. Choosing which unit testing framework to use comes down to experience and your own goals. Currently, the most common framework is nUnit and this is an excellent starting point.

Another popular testing framework is MbUnit, which focuses on extendibility and data-driven tests while being compatible with the nUnit syntax.

MSTest is the framework included as part of Visual Studio 2005 and 2008 and has slightly different syntax to nUnit. Instead of TestFixture attribute, it is called TestClass and instead of the Test attribute you need to use TestMethod.

Finally, the newest framework is xUnit.NET. xUnit is a very effective framework, which takes a different approach and view to the other frameworks. The syntax is also slightly different; for example you don't need to specify the TestFixture attribute, and instead of specifying the Test attribute, you use the Fact attribute. The reason for this name change is that both Brad Wilson and James Newkirk, the creators of xUnit, feel that unit tests should actually document "facts" about the code. As such, if the unit test fails, then the fact is wrong. Although this is a different view, it is actually logical. The reason for the name change is because the creators do not view each method as a test for the code; ...

Get Testing ASP.NET Web Applications now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.