The question aims to find a better solution than mine.
I have the following REQUIREMENTS for my integration tests:
- Each integration test i simplemented in a single test class.
- The methods in a test class have to be executed in order.
- Each method is one step of the integration test.
- If a test method fails all other test methods in the test class have to be skipped - because it does not make sense to find subsequent errors.
MY SOLUTION looks like this:
I just inherit every test class from my abstract test class:
package com.lidl.eu.lisa.test.junit.test;
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...
Aucun commentaire:
Enregistrer un commentaire