Posted By:
Anonymous
Posted On:
Tuesday, February 8, 2005 09:48 AM
More of a code sample would help, but I think I know what the issue is.
The TestRunner.run() methods are static. They create their own new instance of a TestRunner and then call doRun().
I t*h*i*n*k what you need to do is call a doRun() method instead.
I grabbed this TestRunner code from a google search, didn't look at the source on my machine, so buyer beware.
....
/**
* Runs a suite extracted from a TestCase subclass.
*/
static public void run(Class testClass) {
run(new TestSuite(testClass));
}
/**
* Runs a single test and collects its results.
* This method can be used to start a test run
* from your program.
*
* public static void main (String[] args) {
* test.textui.TestRunner.run(suite());
* }
*
*/
static public TestResult run(Test test) {
TestRunner runner= new TestRunner();
return runner.doRun(test);
}
....
public TestResult doRun(Test test) {
return doRun(test, false);
}
public TestResult doRun(Test suite, boolean wait) {
TestResult result= createTestResult();
result.addListener(fPrinter);
long startTime= System.currentTimeMillis();
suite.run(result);
long endTime= System.currentTimeMillis();
long runTime= endTime-startTime;
fPrinter.print(result, runTime);
pause(wait);
return result;
}