private void setAllFailedScenariosToStatusFailed(Result result) { for (Failure failure : result.getFailures()) story .scenarioDescribedBy(failure.getDescription()) .withStatus(ScenarioStatus.FAILED.withDetails(failure.getException())); }
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()); }