Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Spring Test / Concordion integration - integrate Concordion with Spring's test runner
package testsupport;
import org.concordion.api.ResultSummary;
import org.concordion.internal.FixtureRunner;
import org.junit.runner.Description;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.Statement;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ConcordionSpringJunit4ClassRunner extends SpringJUnit4ClassRunner {
private final Description fixtureDescription;
private final FrameworkMethod fakeMethod;
private ResultSummary result;
public ConcordionSpringJunit4ClassRunner(Class<?> fixtureClass) throws InitializationError, NoSuchMethodException {
super(fixtureClass);
String testDescription = ("[Concordion Specification for '" + fixtureClass.getSimpleName()).replaceAll("Test$", "']");
fixtureDescription = Description.createTestDescription(fixtureClass, testDescription);
fakeMethod = new FrameworkMethod(this.getClass().getDeclaredMethod("computeTestMethods"));
}
@Override
protected List<FrameworkMethod> computeTestMethods() {
return new ArrayList<FrameworkMethod>(Arrays.asList(fakeMethod));
}
@Override
protected Statement methodInvoker(FrameworkMethod method, final Object test) {
return new Statement() {
public void evaluate() throws Throwable {
result = new FixtureRunner().run(test);
}
};
}
@Override
protected Description describeChild(FrameworkMethod method) {
return fixtureDescription;
}
}
// ConcordionSpringJunit4ClassRunner supports everything that is supported by Spring & Concordion
@RunWith( ConcordionSpringJunit4ClassRunner.class )
@ContextConfiguration("/test-applicationContext.xml")
@Transactional
@Ignore
public class MyConcordionSpecification
{
@Autowired
MyClassUnderTest instanceUnderTest;
// ... whatever
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment