Game Development Reference
In-Depth Information
Table 10.2 Unit Testing Benefits
Benefit
Description
Requires the programmer to slow down and think
When refactoring or adding a new
feature, testing forces you to think about
what the code is supposed to do. You end
up thinking about how the public API is
accessed and what the outcome should
be, ending up with a clean design that
does exactly what you expect it to do.
Protects you against other programmers
Sometimes bugs only manifest themselves
in rare situations. If another programmer
changes a class but does not run the new
code with all the problematic situations,
bugs may slip through. If a unit test exists
to test that particular situation, then the
bug will be found when the unit tests are
run again after changing the code.
Forces you to design better code
Testing forces you to make your code easy
to test, relying less on the usage of
singletons and global variables. Tightly
coupled design is often difficult to test and
generally requires complex initialization.
Testing generally enforces loosely coupled
design to make testing easier.
Promotes refactoring without breaking code
Testing allows you to refactor at any time
without the fear of breaking your code, so
that the design of your program can
improve over numerous iterations. Each
time the code is changed, the tests are
run again to ensure that all the existing
modules remain stable.
Introducing NUnit
In order to properly perform unit testing, a framework must be employed to facil-
itate the testing. This is where NUnit comes into play. NUnit is a unit testing tool
for the Microsoft .NET Framework. It targets test-driven development with all .NET
languages, including C#, Visual Basic .NET, J#, and C++/CLI.
NUnit was developed by Jim Newkirk, Alexei Vorontsov, Michael Two, and Charlie
Pool, based on the original NUnit version by Philip Craig. NUnit is very similar to
the eXtreme Programming test frameworks (xUnits) with a couple of significant
differences.
Search Nedrilad ::




Custom Search