Organize the tests hierarchically the way you want them displayed in the test tree. The Test Manager in the harness displays the test hierarchy, enabling users to select and run specific groups of tests from the GUI.

Test Class

A test class or test source is a Java technology class that either implements the test interface or extends the test class. A test class can rely on inner, sub, or independent classes and contains one or more test cases. Users must add individual test case methods to the derived test class to create a useful test class.

See Chapter 4 for information required to write different types of tests for the Framework.

Test Case

A test case represents a single test and is the smallest test entity. If a test class defines only one test case, the test class is equivalent to the test case. Each test case must return a Status object that represents the outcome of the test case.

The following example shows a very simple test class which contains several test cases.

CODE EXAMPLE 3-2 Simple Test Class

public class MyTest extends MultiTest {

protected void runTestCases() { if (isSelected("testCase1")) {

addStatus(testCase1());

}

if (isSelected("testCase2")) { addStatus(testCase2());

}

}

public Status testCase1() { if (1 + 1 == 2)

return Status.passed("OK");

else

return Status.failed("1 + 1 did not make 2");

}

}

public Status testCase2() { if (2 + 2 == 4)

26 Java ME TCK Framework Developer’s Guide • July 2007

Page 46
Image 46
Sun Microsystems 1.2 manual Test Class, Test Case