Reputation: 3377
The question aims to find a better solution than mine.
I have the following REQUIREMENTS for my integration tests:
MY SOLUTION looks like this:
I just inherit every test class from my abstract test class:
package myPackage;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TestWatcher;
public abstract class FailFastTest {
private final static List<Class<?>> FAILED_CLASSES = new CopyOnWriteArrayList<Class<?>>() ;
private final Class<? extends FailFastTest> thatClass = this.getClass();
@Rule
public final TestWatcher onFailedRule = new TestWatcher() {
protected void failed(Throwable e, org.junit.runner.Description description) {
FAILED_CLASSES.add(thatClass);
};
};
@Before
public final void beforeMethod() {
final boolean failed = FAILED_CLASSES.contains(thatClass);
if(failed) {
System.out.println(thatClass + " FAILED. Aborting test.");
org.junit.Assume.assumeTrue(!failed);
}
}
}
Does anybody have a better idea? My PROBLEM: I cannot run such a test class multiple times in parallel because of the classname signals the skipping...
NO! It is not a duplicate! I try to write functional tests which use different (web-)services in a specific order. The Question "How do I test a servlet?" is quite different!
Anyway. I switched to TestNG. TestNG supports all requirements I have and works like charm. I do not need my glue code any longer!
Upvotes: 1
Views: 121