use of org.kanonizo.junit.runners.JUnit3TestRunner in project kanonizo by kanonizo.
the class TestCase method run.
/**
* Executes a single test method on the JUnitCore class, using default
* Runners and configuration. This method must reload the class from the
* class loader as it will have been instrumented since it is first created.
* If the instrumented version is not loaded, code coverage goes a little
* bit funky.
*
* @throws ClassNotFoundException if the ClassLoader can't find the {@link #testClass} by name
*/
public void run() {
long startTime = System.currentTimeMillis();
// reload testclass from memory class loader to get the instrumented
// version
Task timerTask = new TestCaseExecutionTimer(testClass.getName(), testMethod.getName());
if (InstrumentationProperties.LOG) {
TaskTimer.taskStart(timerTask);
}
File rootFolder;
if (EXECUTE_IN_ROOT_FOLDER && (rootFolder = Framework.getInstance().getRootFolder()) != null) {
System.setProperty("user.dir", rootFolder.getAbsolutePath());
}
KanonizoTestRunner testCaseRunner = TestingUtils.isJUnit4Class(testClass) ? new JUnit4TestRunner() : new JUnit3TestRunner();
KanonizoTestResult result = null;
if (USE_TIMEOUT) {
ExecutorService service = Executors.newSingleThreadExecutor();
Future<KanonizoTestResult> res = service.submit(() -> testCaseRunner.runTest(this));
try {
result = res.get(TIMEOUT, UNIT);
} catch (TimeoutException e) {
logger.debug("Test " + testMethod.getName() + " timed out.");
return;
} catch (InterruptedException e) {
logger.error(e);
} catch (ExecutionException e) {
logger.error(e);
}
} else {
result = testCaseRunner.runTest(this);
}
setResult(result);
if (InstrumentationProperties.LOG) {
TaskTimer.taskEnd(timerTask);
}
}
Aggregations