nl.hsac.fitnesse.junit.JUnitConsoleRunner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hsac-fitnesse-fixtures Show documentation
Show all versions of hsac-fitnesse-fixtures Show documentation
Fixtures to assist in testing via FitNesse
package nl.hsac.fitnesse.junit;
import fitnesse.junit.JUnitXMLPerPageRunListener;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.RunListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Runs JUnit tests from the command line, with RunListeners attached.
*/
public class JUnitConsoleRunner {
protected List getListeners() {
return Arrays.asList(new JUnitXMLPerPageRunListener(), new ProgressLoggerListener());
}
protected List getTestClasses(String[] args) {
List classes = new ArrayList<>();
for (String arg : args) {
try {
classes.add(Class.forName(arg));
} catch (ClassNotFoundException e) {
throw new RuntimeException("Unable to create instance of: " + arg);
}
}
return classes;
}
public Result runTests(String... args) {
JUnitCore core = new JUnitCore();
for (RunListener r : getListeners()) {
core.addListener(r);
}
List classes = getTestClasses(args);
return core.run(classes.toArray(new Class[classes.size()]));
}
public static void main(String[] args) {
if (args.length == 0) {
System.err.println("No test class names provided as argument.");
System.exit(-1);
}
Result r = new JUnitConsoleRunner().runTests(args);
System.exit(r.wasSuccessful()? 0 : 1);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy