Adding test methods
This topic demonstrates how to add a test method to a JUnit test through an example.
In this example, a TPTP JUnit Test must be created with the
following test methods: testAccount; testOrder; and testInvoice. The test must run testAccount and testOrder in a loop iterated 3 times,
and then run testInvoice.
Adding the Test Methods to the JUnit Test
Select the Test Methods tab. Click on the Add button and replace the automatically created test
1 method with testAccount by editing the value in the Name text box. Read about the other widgets on this page in the JUnit Test Editor
topic.
Repeat to add testOrder and testInvoice.
Associate test methods with the loop
To associate test methods with the loop created earlier, switch to the Behavior tab, select the loop, click on the Add... button, and select invocation.
Now select testAccount and testOrder (press
<ctrl>-click on each to select both) from the Test Invocation dialog. (Note that tests can be selected from a different suite in
the workspace.)
Click OK. testAccount and testOrder will now be embedded in the
loop.
To include the testInvoice test method, stop selecting Loop
1, click Add..., select testInvoice, and click on OK. The Behavior should look like the screen capture below: a loop containing an invocation to testAccount and to testOrder, and following the loop an invocation to testInvoice.
The Associated Java
The behavior process results in TPTP creating Java source
which, when run, emulates the specified test behavior. The Java source is given
the same name as the TPTP JUnit Test but of type .java (SimpleTest.java) and
it contains within in it stubs for the testAccount, testOrder, and testInvoice
methods. For example, the testAccount method looks like:
public void testAccount() throws Exception
{
// Enter your code here
}
The necessary code for the test should be inserted where the comment is (//
Enter your code here).
Related concepts
JUnit Test Editor