| Overview of the tester use | |||||||||||||||||||||||||||
The tester package supports the design of tests for a program that consists of a collection of
multiple classes and interfaces. A typical test suite consists of sample data for each class in the class hierarchy
followed by the unit tests for every method in every class in the class hierarchy. The class where the tests are
defined (typically called The tests are designed to check whether the given actual value is the same as the expected value, comparing the objects for extensional equality. The comparison of two instances of objects in the same class is based on comparing the values of the corresponding fields. For complex data this comparison is replicated for each field that is an instance of another class. The comparison of inexact values requires that the programmer invokes the
Absolute tolerance is used when comparing an inexact value with a For data collections that implement the The design of tests for data collections that implement the
There is a support for comparing inexact numerical values, wrapper classes, for testing whether a method invocation, or a constructor invocation threw the desired exception, and for tests where the programmer defines the meaning of equality for one class within the class hierarchy, or for any two objects. Tests that determine whether the actual value is one of several possible values are also supported,
as are tests for checking whether the actual value is within the given range of values, using either
The test report shows the number of test
that have been performed, the number of tests that failed, and for every failed test it shows both the actual and the
expected values, and provides a link to the place where the failed test is located. Additionally, the report includes a
display of all data that have been defined as fields of the If the user implements The following
import tester.*;
class Examples{
Examples(){}
Flight bos_phi = new Flight("BOS", "PHI", 8, 10);
Flight phi_hst = new Flight("PHI", "HST", 11, 13);
Flight hst_sfo = new Flight("HST", "SFO", 14, 15);
Flight dfw_sfo = new Flight("DFW", "SFO", 14, 15);
ILoF bos_sfo = new Flight("BOS", "SFO", 9, 14);
ILoF bos_sfo_3 = new ConsLoF(this.bos_phi,
new ConsLoF(this.phi_hst, this.hst_sfo));
ILoF bos_sfo_err = new ConsLoF(this.bos_phi,
new ConsLoF(this.phi_hst, this.dfw_sfo));
// test the method departsFrom for flight itinerary classes
boolean testDepartsFrom(Tester t){
return
t.checkExpect(bos_phi.departsFrom(), "BOS") &&
t.checkExpect(phi_hst.departsFrom(), "PHI");
}
// test the method departsAfter for flight itinerary classes
void testDepartsAfter(Tester t){
t.checkExpect(bos_phi.departsAfter(7), true);
t.checkExpect(bos_phi.departsAfter(8), false);}
// test the method connectsTo for flight itinerary classes
void testConnectsTo(Tester t){
t.checkExpect(bos_phi.connectsTo(bos_sfo_3), this.phi_hst);
t.checkExpect(bos_phi.connectsTo(bos_sfo), null);
}
}
An instance of the The imperative style where the return type for the test method is
The alternative style where the return type is All test methods allow the user to supply an optional Once the tests have been run the tester package prints first the value of all fields defined
in the
SimpleExamples:
---------------
new SimpleExamples:1(
this.hello = "hello"
this.world = "world"
this.n = 5)
------------------------------
Found 1 test method
Ran 3 tests.
All tests passed.
Test results:
--------------
--- END OF TEST RESULTS ---
or, if errors have been detected the report prints both the actual and the expected value for that test
and includes a link to the relevant line in the test suite:
SimpleExamples:
---------------
new SimpleExamples:1(
this.hello = "hello"
this.world = "world"
this.n = 5)
---------------
Found 1 test methods
Ran 4 tests.
1 test failed.
Test results:
--------------
Error in test number 4
will fail
tester.ErrorReport: Error trace:
at SimpleExamples.testStrings(SimpleExamples.java:12)
actual: expected:
"hello"................................. "world"
--- END OF TEST RESULTS ---
| ||||||||||||||||||||||||||||
| last updated on Mon Apr 4 15:26:25 EDT 2011 | generated with DrRacket |