Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Eclipse Application Testing Guide
Previous Page Home Next Page

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 ( 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

  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire