Game Development Reference
In-Depth Information
It is important to note that this chapter does not attempt to sell you on the idea of
testing, as it is assumed that you have adopted this excellent practice already, since
you are reading the chapter. Additionally, this chapter will only briefly cover the
basics behind unit testing; it will in no way attempt to cover all the fundamentals
of unit testing. The main focus of this chapter is on performing unit tests with the
NUnit framework and application.
Overview of Unit Testing
Basically, unit testing focuses on a single unit—the class. Each class is tested alone
in an attempt to discover errors in its code. The idea is to test anything in a class
that could conceivably fail. If something in the class is changed, all tests, not just
your own, are run again. If any fail, the programmer immediately goes back, fixes
the problem, and runs the tests again. This process is performed in an iterative
manner until all tests are successful.
After unit testing is complete on a group of modules, they are combined into pro-
gressively more complex groupings, which are also tested. This integration processes
will continue until the entire application has been assembled and tested.
There are two main approaches when performing unit testing, as discussed in
Table 10.1.
Table 10.1 Unit Testing Approaches
Black-Box Approach
The black-box approach is the most commonly used method, in which
each class represents an encapsulated object. The black-box approach
is driven by all the preconstruction specifications for each class.
Each item in the specification becomes a test, and several test cases
are developed for it. The tests are focused on whether or not the class
meets the requirements in the specification, rather than the
programmer's interpretation.
White-Box Approach
The white-box approach is based on the method specifications
associated with each class. The white-box approach is generally used
instead of the black-box approach when the complexity of the class is
high. The tester may discover errors or assumptions by looking through
the code that are not generally obvious to a tester using the black-box
There are quite a few benefits to unit testing, but some of the most notable ones
are discussed in Table 10.2.
Search Nedrilad ::

Custom Search