Java Reference
In-Depth Information
Test assertions
While recording a test method, any method calls that return a result will bring up a Method
Result window. This offers the opportunity to make an assertion about the result value by tick-
ing the Assert that box. A drop-down menu contains a set of possible assertions for the result
value. If an assertion is made, this will be encoded as a method call in the test method which is
intended to lead to an AssertionError if the test fails.
Running tests
Individual test methods can be run by selecting them from the pop-up menu associated with the
test class. A successful test will be indicated by a message in the main window's status line. An
unsuccessful test will cause the Test Results window to appear. Selecting Test All from the test
class's pop-up menu runs all tests from a single test class. The Test Results window will detail
the success or failure of each method.
The contents of the object bench may be captured as a fixture by selecting Object Bench to Test
Fixture from the pop-up menu associated with the test class. The effect of creating a fixture is
that a field definition for each object is added to the test class, and statements are added to its
setUp method that re-create the exact state of the objects as they were on the bench. The ob-
jects are then removed from the bench.
The setUp method has the annotation @Before in the test class and the method is automati-
cally executed before the run of any test method, so all objects in a fixture are available for all
The objects of a fixture may be re-created on the object bench by selecting Test Fixture to
Object Bench from the test class's menu.
A tearDown method, with the annotation @After , is called following each test method. This
can be used to conduct any post-test housekeeping or clean-up operations, should they be
Search WWH ::

Custom Search