Information Technology Reference
In-Depth Information
fully implemented, automated build and CI system using the Integrate
button illustration.
People often use the term “unit test” rather broadly. This can cause
confusion, especially when people start claiming their unit tests “take
too long to run.” Defining a common vocabulary for developer tests
can assist in categorizing them into efficient groups, which can make
all the difference in creating an effective CI system capable of running
fast builds.
Unit tests
verify the behavior of small elements in a software sys-
tem, which are most often a single class. Occasionally, though, the
one-to-one relationship between a unit test and a class is slightly aug-
mented with additional classes because the classes under test are
tightly coupled.
Listing 6-1 shows a unit test written with the TestNG framework.
TestNG is annotation-based, hence the
@testng.test
Javadoc-like
comment in the
starPatternTest
method. This test case verifies, via
Java 1.4's
assert
capability, that the class
RegexPackageFilter
properly filters strings via a regular expression pattern.
LISTING 6-1
Isolated Unit Test Using TestNG
public class RegexPackageFilterTestNG {
/**
*
@testng.test
*/
public void starPatternTest() throws Exception{
Filter filter = new RegexPackageFilter("java.lang.*");
assert filter.applyFilter("java.lang.String"):
"filter returned false";
assert !filter.applyFilter("org.junit.TestCase"):
"filter returned true for org.junit.TestCase";
}
}