public static void usage() { System.out.println( "usage: java dbxmltest.XmlTestRunner" + " [-c whole|node|all] [-e none|txn|cds|all]" + " [test1 [test2 ..]]"); System.exit(-1); }
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); }
public static void main(String[] arg) { Vector<Boolean> containerTypes = new Vector<Boolean>(); Vector<String> environmentTypes = new Vector<String>(); Vector<String> testNames = new Vector<String>(); Vector<Class> argTests = new Vector<Class>(); Class[] tests = {}; for (int i = 0; i < arg.length; i++) { if (arg[i].startsWith("-")) { switch (arg[i].charAt(1)) { case 'c': String cType = arg[++i]; if (cType.equalsIgnoreCase(NODE)) containerTypes.add(true); else if (cType.equalsIgnoreCase(WHOLE)) containerTypes.add(false); else if (cType.equalsIgnoreCase(ALL)) { containerTypes.add(true); containerTypes.add(false); } else usage(); break; case 'e': String eType = arg[++i]; if (eType.equalsIgnoreCase(NONE) || eType.equalsIgnoreCase(TXN) || eType.equalsIgnoreCase(CDS)) environmentTypes.add(eType); else if (eType.equalsIgnoreCase(ALL)) { environmentTypes.add(NONE); environmentTypes.add(TXN); environmentTypes.add(CDS); } else usage(); break; default: usage(); } } else testNames.add(arg[i]); } if (containerTypes.size() == 0) { containerTypes.add(true); containerTypes.add(false); } if (environmentTypes.size() == 0) { environmentTypes.add(NONE); environmentTypes.add(TXN); environmentTypes.add(CDS); } // Get the tests to run if (testNames.size() != 0) { for (int i = 0; i < testNames.size(); i++) { Class testClass = null; try { testClass = Class.forName("dbxmltest." + testNames.get(i)); } catch (ClassNotFoundException e) { System.out.println("Skipping test " + testClass + ". Test not found."); } if (testClass != null) argTests.add(testClass); } if (argTests.size() != 0) tests = argTests.toArray(tests); else tests = allTests; } else tests = allTests; // Run the tests int failureCount = 0; boolean success = true; File errorFile = new File(getEnvironmentPath() + "/errorLog.txt"); try { if (errorFile.exists()) errorFile.delete(); errorFile.createNewFile(); System.setErr(new PrintStream(new FileOutputStream(errorFile))); } catch (IOException e) { } for (int j = 0; j < environmentTypes.size(); j++) { System.out.println("Testing env type " + environmentTypes.get(j)); for (int i = 0; i < containerTypes.size(); i++) { System.out.println("\tContainer type " + (containerTypes.get(i) ? "node" : "whole")); NODE_CONTAINER = containerTypes.get(i); ENV_TYPE = environmentTypes.get(j); Result res = org.junit.runner.JUnitCore.runClasses(tests); if (!res.wasSuccessful()) { System.err.println( "Number of failures for environment type " + ENV_TYPE + " and is node container " + NODE_CONTAINER + " are " + res.getFailureCount()); List<Failure> testFailures = res.getFailures(); ListIterator<Failure> iter = testFailures.listIterator(); while (iter.hasNext()) { Failure fail = iter.next(); System.err.println(fail.getDescription()); Throwable e = fail.getException(); if (e != null) e.printStackTrace(); else System.err.println(fail.getTrace()); } failureCount += res.getFailureCount(); success = res.wasSuccessful(); } } } if (success) System.out.println("All tests successful."); else System.out.println(failureCount + " tests failed."); System.out.println("Failures printed to " + errorFile.getName()); }