{
TestResult result = new TestResult();
XMLJUnitResultFormatter resultFormatter = new XMLJUnitResultFormatter();
JUnitTest dummyJUnit = new JUnitTest(name);
resultFormatter.startTestSuite(dummyJUnit);
OutputStream writer = new FileOutputStream(new File(reportFile));
resultFormatter.setOutput(writer);
result.addListener(resultFormatter);
TestSuite suite = new TestSuite();
JUnitClientTest test = null;
try
{
test = (JUnitClientTest) Class.forName(testClass).newInstance();
}
catch (ClassCastException e)
{
System.err.println("Class " + testClass + " does not implement " + JUnitClientTest.class.getName());
}
catch (ClassNotFoundException e)
{
System.err.println("Cannot locate class " + testClass);
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
catch (InstantiationException e)
{
System.err.println("Class " + testClass + " cannot be instantiated: " + e.getMessage());
}
test.setName("testAction");
test.init(config, params, isDebug);
suite.addTest(test);
long startTime = new Date().getTime();
suite.run(result);
long endTime = new Date().getTime();
dummyJUnit.setCounts(result.runCount(), result.failureCount(), result.errorCount());
dummyJUnit.setRunTime(endTime - startTime);
resultFormatter.endTestSuite(dummyJUnit);
writer.close();