Game Development Reference
In-Depth Information
Just like .NET, the NUnit framework is language-independent, in the sense that
any CLR-compliant language may be used to write tests and NUnit will execute
them just fine.
Attributes are a wonderful feature of .NET, and are used by NUnit to identity tests
and test fixtures, without requiring that tests inherit from classes within a testing
framework. Using attributes to define tests allows code to remain clean and fairly
independent of any test support files.
With the creation of tests, you perform the testing by launching either the GUI or
console version of the NUnit application, and target the assemblies that you wish
to test. NUnit uses reflection to interrogate the assemblies for tests and then exe-
cutes them one at a time. All tests have the ability to execute setup and teardown
methods, allowing for each test to be independent of the others.
Creating an NUnit Project
There are a few ways you can develop your unit tests. Some developers prefer to
place test functions directly inside the source code of the project that is being test-
ed. If this is something you wish to do, be sure to use the #if and #endif pre-
processor tags to strip unit tests from release mode.
Other developers like to place tests inside separate files within the project being
tested. Again, don't forget to strip these tests out in release mode.
The most common approach, unless you're testing internal objects, is to build your
tests in external assemblies. The benefit to this approach is that all test code is
decoupled from the project itself.
Use whichever method you are comfortable with. The example for this chapter has
the test code in a separate assembly. Start by creating a new class library project for
your unit test assembly.
The next thing to do is reference nunit.framework.dll in your unit test assembly. If
you installed NUnit using the typical approach, you should have all the NUnit
assemblies installed into the Global Assembly Cache (GAC). If not, you can press
the Browse button and manually navigate to the assembly in the installation fold-
er. The default installation path for the NUnit framework is C:\Program
Files\NUnit 2.2\bin.
Figure 10.1 shows the Add Reference dialog with the nunit.framework assembly
showing up in the GAC.
Search Nedrilad ::




Custom Search