//The actual tests
for (Class<? extends ITest> clazz : classes) {
log.info("Starting test class " + clazz.getSimpleName());
try {
ITest test = (ITest) (this.getClass().getClassLoader().loadClass(clazz.getName())).newInstance();
log.trace("Initializing test class for first time (" + test.getClass().getSimpleName() + ")");
test.init();
//Each test-method inside a test-class
Method[] methods = test.getClass().getMethods();
for (Method method : methods) {
if (ReflectionUtils.getAnnotation(Test.class, method) != null) {
try {
int repeats = 1;
int size = Settings.TEST_LOOPS;
int leftOvers = 0;
long totalDuration = 0L;
boolean noGC = false;
if (ReflectionUtils.getAnnotation(NotInfinite.class, method) != null) {
size = ReflectionUtils.getAnnotation(NotInfinite.class, method).invocations();
repeats = Settings.TEST_LOOPS / size;
leftOvers = Settings.TEST_LOOPS % size;
noGC = ReflectionUtils.getAnnotation(NotInfinite.class, method).noGC();
log.trace("NotInfinite annotation found on " + test.getClass().getSimpleName() + "#" + method.getName() + ". {size=" + size + ",repeats=" + repeats + ",leftOvers=" + leftOvers + "}");
}
long start;
for (int i = 0; i < repeats; ++i) {
start = System.currentTimeMillis();
for (int j = 0; j < size; ++j) {
method.invoke(test);
}
totalDuration += (System.currentTimeMillis() - start);
test.init();
if (!noGC) {
GCManager.gc();
}
}
if (leftOvers != 0) { //TODO: remove repeats
start = System.currentTimeMillis();
for (int j = 0; j < leftOvers; ++j) {
method.invoke(test);
}
totalDuration += (System.currentTimeMillis() - start);
}
log.trace("Test finished (" + test.getClass().getSimpleName() + "#" + method.getName() + ")");
addResult(new Result(test.getClass(), method, totalDuration), test.getClass().getAnnotation(TestSuite.class));
if (ReflectionUtils.getAnnotation(DirtiesObject.class, method) != null) {
log.trace("DirtiesObject annotation found on " + test.getClass().getSimpleName() + "#" + method.getName() + ": reinitializing");
test.init();
}
} catch (InvocationTargetException e) {
log.error("Failed to invoke testmethod " + test.getClass().getSimpleName() + "#" + method.getName() + ": " + e.getMessage(), e);
addResult(new Result(test.getClass(), method, Long.MIN_VALUE), test.getClass().getAnnotation(TestSuite.class));
}
} else {
if (method.getName().startsWith("test")) {
log.warn("Method " + method.getName() + " skipped");
} else {
log.trace("Method " + method.getName() + " skipped");
}
}
}
//Test-class finished, clear resources and go to next test-class
log.trace("Test finished");
test.destroy();
test = null;
GCManager.forceGC();
} catch (InitializationException e) {
log.error("Failed to initialize test " + clazz.getSimpleName() + ": " + e.getMessage(), e);
} catch (InstantiationException e) {