Java Reference
In-Depth Information
If the actual value isn't equal to the expected value, JU nit throws an unchecked
exception, which causes the test to fail.
Most often, the delta parameter can be zero, and we can safely ignore it. It comes
into play with calculations that aren't always precise, which includes many floating-
point calculations. The delta provides a range factor. If the actual value is within the
range expected - delta and expected + delta , the test will pass. You may find it use-
ful when doing mathematical computations with rounding or truncating errors or
when asserting a condition about the modification date of a file, because the precision
of these dates depends on the operating system.
Let's assume that we've entered the code from listings 1.1 and 1.4 in the C:\junit-
book\ch01-jumpstart directory (/opt/junitbook/ch01-jumpstart on UNIX ). Let's first
compile the code by opening a command shell in that directory and typing the follow-
ing (we'll assume we have the javac executable on our PATH ):
Windows
javac -cp \junit4.6\junit-4.6.jar *.java
UNIX
javac -cp /opt/junit4.6/junit-4.6.jar *.java
We're now ready to start the console test runner, by typing the following:
Windows
java -cp .;\junit4.6\junit-4.6.jar
org.junit.runner.JUnitCore CalculatorTest
UNIX
java -cp .:/opt/junit4.6/junit-4.6.jar
org.junit.runner.JUnitCore CalculatorTest
Figure 1.2 shows the test result.
Figure 1.2
Execution of the first JUnit test CalculatorTest using the text test runner
 
 
Search WWH ::




Custom Search