public class JUnitListener extends RunListener { private PrintWriter pw; private String outputFile = System.getProperty("junit.output.file"); public void testRunStarted(Description description) throws Exception { pw = new PrintWriter(new FileWriter(outputFile)); pw.println("testRunStarted"); } public void testRunFinished(Result result) throws Exception { pw.println("testRunFinished"); pw.close(); } public void testStarted(Description description) throws Exception { pw.println("testStarted " + description.getDisplayName()); } public void testFinished(Description description) throws Exception { pw.println("testFinished " + description.getDisplayName()); } public void testFailure(Failure failure) throws Exception { pw.println("testFailure " + failure.getDescription().getDisplayName()); } public void testAssumptionFailure(Failure failure) { pw.print("ASSUMPTION FAILURE"); } public void testIgnored(Description description) throws Exception { pw.println("testIgnored " + description.getDisplayName()); } }
private void generateReport() { fileWriter = null; if ("scenarios".equals(shouldGenerateFile())) fileWriter = new ScenariosFileWriter(); else if ("html".equals(shouldGenerateFile())) fileWriter = new FreemarkerFileWriter(); if (fileWriter != null) { fileWriter.setOutputFolder(System.getProperty("outputFolder")); fileWriter.write(story); fileWriter.writeToc(storiesList); } }
private String shouldGenerateFile() { return System.getProperty(GENERATE_FILES); }