Methods Summary |
---|
public void | assertEquals(java.lang.Object expected, java.lang.Object actual)Asserts that two objects are equal according to the equals() method.
assertEquals(null, expected, actual);
|
public void | assertEquals(java.lang.String message, java.lang.Object expected, java.lang.Object actual)Asserts that two objects are equal according to the equals() method.
Two null references are considered to be equal.
boolean isequal = (expected == actual);
// If references aren't identical, call equals() only when
// both references are non-null.
if (!isequal && expected != null && actual != null) {
isequal = expected.equals(actual);
}
assertTrue(message, isequal);
if (!isequal) {
p(" expected: " + expected + "; actual: " + actual);
}
|
public void | assertEquals(int expected, int actual)Asserts that two integer values are equal.
assertEquals(null, expected, actual);
|
public void | assertEquals(java.lang.String message, int expected, int actual)Asserts that two integer values are equal.
assertTrue(message, expected == actual);
if (expected != actual) {
p(" expected: " + expected + "; actual: " + actual);
}
|
public void | assertFalse(boolean condition)Asserts that condition is false.
assertTrue(null, !condition);
|
public void | assertFalse(java.lang.String message, boolean condition)Asserts that condition is false.
assertTrue(message, !condition);
|
public void | assertNotNull(java.lang.Object object)Asserts that the object reference is not null.
assertTrue(null, object != null);
|
public void | assertNotNull(java.lang.String message, java.lang.Object object)Asserts that the object reference is not null.
assertTrue(message, object != null);
|
public void | assertNotSame(java.lang.Object expected, java.lang.Object actual)Asserts that two references do not point to the same object,
using the == operator.
assertNotSame(null, expected, actual);
|
public void | assertNotSame(java.lang.String message, java.lang.Object expected, java.lang.Object actual)Asserts that two references do not point to the same object,
using the == operator.
assertTrue(message, expected != actual);
if (expected == actual) {
p(" expected: " + expected + "; actual: " + actual);
}
|
public void | assertNull(java.lang.Object object)Asserts that the object reference is null.
assertNull(null, object);
|
public void | assertNull(java.lang.String message, java.lang.Object object)Asserts that the object reference is null.
assertTrue(message, object == null);
if (object != null) {
p(" actual: " + object);
}
|
public void | assertSame(java.lang.Object expected, java.lang.Object actual)Asserts that two references point to the same object, using the
== operator.
assertSame(null, expected, actual);
|
public void | assertSame(java.lang.String message, java.lang.Object expected, java.lang.Object actual)Asserts that two references point to the same object, using the
== operator.
assertTrue(message, expected == actual);
if (expected != actual) {
p(" expected: " + expected + "; actual: " + actual);
}
|
public void | assertTrue(java.lang.String message, boolean condition)Tests the assertion that the boolean condition is true.
If the condition is true, this method simply updates some statistics
and returns. If the condition is false, the failure is noted and the
message is emitted, along with an indication of the current TestCase
and the name of the test currently being run. The
message string should be phrased in a way that makes sense
when the test fails. See the example in the class documentation.
if (currentTest == null) {
p("ERROR assert \"" + message + "\" not part of any test");
errorAssertWithoutTest++;
return;
}
currentNumAsserts++;
totalAsserts++;
if (verbose) {
p("## " + totalAsserts + ": " + message);
}
if (!condition) {
totalFailures++;
String m = "FAIL " + currentTestCaseName();
if (currentTest != null) {
m += "#" + currentTest;
}
if (message != null) {
m += ": " + message;
}
p(m);
}
|
public void | assertTrue(boolean condition)Asserts that condition is true.
assertTrue(null, condition);
|
static void | cleanup()Cleanup after running a test.
if (currentTest == null) {
p("ERROR " + currentTestCaseName() + " has no tests");
errorNoTests++;
} else if (currentNumAsserts == 0) {
p("ERROR no asserts in test case " + currentTestCaseName() +
" test " + currentTest);
errorTestWithoutAssert++;
}
currentTestCase = null;
currentTest = null;
|
static java.lang.String | currentTestCaseName()Return the name of the current test case.
return currentTestCase.getClass().getName();
|
public void | declare(java.lang.String testName)Declares that the set of assertions that follow this call belong to a
test named testName . The framework considers it an error
if no calls to any of the assert() methods follow a call to declare().
if (testName == null) {
throw new NullPointerException("test name is null");
}
if (verbose) {
p("## test " + testName);
}
if (currentNumAsserts == 0 && currentTest != null) {
p("ERROR no asserts in test case " + currentTestCaseName() +
" test " + currentTest);
errorTestWithoutAssert++;
}
currentTest = testName;
totalTests++;
currentNumAsserts = 0;
|
public void | fail()Signals an unconditional assertion failure.
assertTrue(null, false);
|
public void | fail(java.lang.String message)Signals an unconditional assertion failure.
assertTrue(message, false);
|
protected com.sun.midp.security.SecurityToken | getSecurityToken()Gets the system's internal security token. This is useful for testing
sensitive interfaces that require a security token parameter. This
returns a valid security token only when called within the context of a
call to runTests() inside a TestCase. At other times it will throw a
SecurityException.
if (tokenEnabled) {
return internalSecurityToken;
} else {
throw new SecurityException();
}
|
protected boolean | getVerbose()Reads the verbose flag.
return verbose;
|
public void | info(java.lang.String s)If in verbose mode, print information.
if (verbose) {
p(".# "+s);
}
|
static void | p(java.lang.String s)Print the string.
System.out.println(s);
|
static void | perror(int nerr, java.lang.String errstr)Print the number of errors with the category.
if (nerr != 0) {
System.out.println(" " + nerr + " " + errstr);
}
|
static void | report()
System.out.print("Test run complete: ");
System.out.print(totalCases
+ (totalCases == 1 ? " testcase " : " testcases "));
System.out.print(totalTests
+ (totalTests == 1 ? " test " : " tests "));
System.out.println(totalAsserts
+ (totalAsserts == 1 ? " assertion" : " assertions"));
if (totalFailures != 0) {
System.out.println(totalFailures
+ (totalFailures == 1 ? " FAILURE!!!" : " FAILURES!!!"));
}
int totalErrors =
errorClassNotFound +
errorNotTestCase +
errorConstructorException +
errorTestRunThrows +
errorNoTests +
errorAssertWithoutTest +
errorTestWithoutAssert;
if (totalErrors != 0) {
System.out.println(totalErrors
+ (totalErrors == 1 ? " ERROR!!!" : " ERRORS!!!"));
perror(errorClassNotFound, "test class not found");
perror(errorConstructorException, "constructor threw exception");
perror(errorNotTestCase, "class not subclass of TestCase");
perror(errorTestRunThrows, "test run threw exception");
perror(errorNoTests, "no tests declared");
perror(errorAssertWithoutTest, "asserts outside of any test");
perror(errorTestWithoutAssert, "tests with no asserts");
}
|
static void | reset()Reset the counters of all errors and exceptions.
totalCases = 0;
totalTests = 0;
totalAsserts = 0;
totalFailures = 0;
currentNumAsserts = 0;
errorClassNotFound = 0;
errorConstructorException = 0;
errorNotTestCase = 0;
errorTestRunThrows = 0;
errorNoTests = 0;
errorAssertWithoutTest = 0;
errorTestWithoutAssert = 0;
|
static void | runTestCase(java.lang.String testCaseName)Run the named test case.
// ==================== static implementation ====================
Class clazz;
Object obj;
TestCase tc;
if (verbose) {
System.out.println("## running test case " + testCaseName);
}
try {
clazz = Class.forName(testCaseName);
} catch (ClassNotFoundException cnfe) {
System.out.println(
"ERROR test class " + testCaseName + " not found");
errorClassNotFound++;
return;
}
try {
obj = clazz.newInstance();
} catch (Throwable t) {
System.out.println("ERROR test class " + testCaseName +
" constructor threw " + t);
errorConstructorException++;
return;
}
try {
tc = (TestCase)obj;
} catch (ClassCastException cce) {
System.out.println("ERROR test class " + testCaseName +
" not a subclass of TestCase");
errorNotTestCase++;
return;
}
try {
tokenEnabled = true;
tc.runTests();
} catch (Throwable t) {
String m = "ERROR " + currentTestCaseName();
if (currentTest != null) {
m += "#" + currentTest;
}
m += " threw " + t;
p(m);
t.printStackTrace();
errorTestRunThrows++;
}
tokenEnabled = false;
cleanup();
|
public abstract void | runTests()Runs all the tests for this TestCase. This is an abstract method that
must be implemented by the subclass. The implementation of this method
should run all of the tests provided in this TestCase. This method can
also be used to initialize and tear down any state that might need to
be shared among all the tests.
A suggested organization is to have runTests() alternate calling
declare() and an internal method that implements the test. One could
write the declare() method as part of the internal test method, but
consolidating all calls in runTests() makes it a little easier to
ensure that each test has its own call to declare(). See the example
in the class documentation.
|
static void | setVerbose(boolean v)Set the verbose output flag.
verbose = v;
|