Home
Creating a JUnit test suite
A JUnit test suite is used to run one or more test cases at once. Application Developer has a simple wizard to create a test suite for JUnit 3.8.1 test cases.
Important: We found that the New JUnit Test Suite wizard does not allow us to select between JUnit 3.8.1 and JUnit 4.x test suites. The wizard can only be used for JUnit 3.8.1 test suites and therefore, it only lets you add JUnit 3.8.1 or lower JUnit version test cases. This is a known Eclipse bug:
http://bugs.eclipse.org/bugs/show_bug.cgi?id=155828We had to create the JUnit test suite for the example manually. Next we provide a step-by-step guide to create a test suite for JUnit 3.8.1 test cases. This guide is just given for completeness and cannot be used for the example.
To create a JUnit 4.x test suite manually, do these steps:
Create a new class called AllTests in the same package. The class extends the default super class java.lang.Object, and does not require any interfaces or method stubs.
Add the import statements and annotations to the AllTests class, as shown in Example | 3-5. The structure of that class is described in Test suite class. Example 23-5 AllTests class: A JUnit 4.x test suite class
package itso.rad75.bank.test.junit;import org.junit.runner.RunWith;import org.junit.runners.Suite;import org.junit.runners.Suite.SuiteClasses;@RunWith(Suite.class)@SuiteClasses({ITSOBankTest.class})public class AllTests {}
In our example we only have added a single test class, and thus a test suite is not required. However, as you add more and more test cases, a test suite quickly becomes a more practical way to manage your unit testing.
To create a JUnit 3.8.1 test suite using the New JUnit Test Suite wizard, do these steps:
Right-click the junit package and select New Æ Other Æ Java Æ JUnit Æ JUnit Test Suite.
In the JUnit Test Suite dialog, enter the following data:
Name: AllTests
Test classes to include in suite: select all test classes which you want to include in this suite.
Click Finish.
ibm.com/redbooks