Java Code Examples for junit.framework.TestResult#wasSuccessful()
The following examples show how to use
junit.framework.TestResult#wasSuccessful() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResultPrinter.java From tomee with Apache License 2.0 | 6 votes |
/** * Prints the header of the report */ public void printHeader(final TestResult result) { if (result.wasSuccessful()) { writer().println(); writer().print("OK"); writer().println(" (" + result.runCount() + " tests)"); } else { writer().println(); writer().println("FAILURES!!!"); writer().println("~~ Test Results ~~~~~~~~~~~~"); writer().println(" Run: " + result.runCount()); writer().println(" Failures: " + result.failureCount()); writer().println(" Errors: " + result.errorCount()); } }
Example 2
Source File: UIMAResultPrinter.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * @see junit.textui.ResultPrinter#printFooter(junit.framework.TestResult) */ protected void printFooter(TestResult result) { if (result.wasSuccessful()) { getWriter().println(); getWriter().print("OK"); getWriter().println( " (" + result.runCount() + " test" + (result.runCount() == 1 ? "" : "s") + ")"); } else { getWriter().println(); getWriter().println("FAILURES!!!"); getWriter().println( "Tests run: " + result.runCount() + ", Failures: " + result.failureCount() + ", Errors: " + result.errorCount()); } getWriter().println(); }
Example 3
Source File: JSR166TestCase.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
protected void printFooter(TestResult result) { if (result.wasSuccessful()) { getWriter().println("OK (" + result.runCount() + " tests)" + " Time: " + elapsedTimeAsString(runTime)); } else { getWriter().println("Time: " + elapsedTimeAsString(runTime)); super.printFooter(result); } }
Example 4
Source File: JSR166TestCase.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Runs all unit tests in the given test suite. * Actual behavior influenced by jsr166.* system properties. */ static void main(Test suite, String[] args) { if (useSecurityManager) { System.err.println("Setting a permissive security manager"); Policy.setPolicy(permissivePolicy()); System.setSecurityManager(new SecurityManager()); } for (int i = 0; i < suiteRuns; i++) { TestResult result = newPithyTestRunner().doRun(suite); if (!result.wasSuccessful()) System.exit(1); System.gc(); System.runFinalization(); } }
Example 5
Source File: SecurityTestSupport.java From groovy with Apache License 2.0 | 5 votes |
protected void executeTest(Class test, Permission missingPermission) { TestSuite suite = new TestSuite(); suite.addTestSuite(test); TestResult result = new TestResult(); suite.run(result); if (result.wasSuccessful()) { if (missingPermission == null) { return; } else { fail("Security test expected an AccessControlException on " + missingPermission + ", but did not receive one"); } } else { if (missingPermission == null) { new SecurityTestResultPrinter(System.out).print(result); fail("Security test was expected to run successfully, but failed (results on System.out)"); } else { //There may be more than 1 failure: iterate to ensure that they all match the missingPermission. boolean otherFailure = false; for (Enumeration e = result.errors(); e.hasMoreElements();) { TestFailure failure = (TestFailure) e.nextElement(); if (failure.thrownException() instanceof AccessControlException) { AccessControlException ace = (AccessControlException) failure.thrownException(); if (missingPermission.implies(ace.getPermission())) { continue; } } otherFailure = true; break; } if (otherFailure) { new SecurityTestResultPrinter(System.out).print(result); fail("Security test expected an AccessControlException on " + missingPermission + ", but failed for other reasons (results on System.out)"); } } } }
Example 6
Source File: JSR166TestCase.java From streamsupport with GNU General Public License v2.0 | 5 votes |
protected void printFooter(TestResult result) { if (result.wasSuccessful()) { getWriter().println("OK (" + result.runCount() + " tests)" + " Time: " + elapsedTimeAsString(runTime)); } else { getWriter().println("Time: " + elapsedTimeAsString(runTime)); super.printFooter(result); } }
Example 7
Source File: JSR166TestCase.java From streamsupport with GNU General Public License v2.0 | 5 votes |
/** * Runs all unit tests in the given test suite. * Actual behavior influenced by jsr166.* system properties. */ static void main(Test suite, String[] args) { if (useSecurityManager) { System.err.println("Setting a permissive security manager"); Policy.setPolicy(permissivePolicy()); System.setSecurityManager(new SecurityManager()); } for (int i = 0; i < suiteRuns; i++) { TestResult result = newPithyTestRunner().doRun(suite); if (!result.wasSuccessful()) System.exit(1); System.gc(); System.runFinalization(); } }
Example 8
Source File: JUnitServlet.java From lams with GNU General Public License v2.0 | 4 votes |
protected void displayResults( PrintWriter writer, TestResult testResult ) { if (!testResult.wasSuccessful()) { displayProblems( writer, "failure", testResult.failureCount(), testResult.failures() ); displayProblems( writer, "error", testResult.errorCount(), testResult.errors() ); } }
Example 9
Source File: TestRunContainer.java From scipio-erp with Apache License 2.0 | 4 votes |
public boolean start() throws ContainerException { // configure log4j output logging if (logLevel != null) { int llevel = Debug.getLevelFromString(logLevel); for (int v = 0; v < 9; v++) { if (v < llevel) { Debug.set(v, false); } else { Debug.set(v, true); } } } // get the tests to run JunitSuiteWrapper jsWrapper = new JunitSuiteWrapper(component, suiteName, testCase); if (jsWrapper.getAllTestList().size() == 0) { throw new ContainerException("No tests found (" + component + " / " + suiteName + " / " + testCase + ")"); } boolean failedRun = false; for (ModelTestSuite modelSuite: jsWrapper.getModelTestSuites()) { Delegator testDelegator = modelSuite.getDelegator(); TestSuite suite = modelSuite.makeTestSuite(); JUnitTest test = new JUnitTest(); test.setName(suite.getName()); // create the XML logger JunitXmlListener xml; try { xml = new JunitXmlListener(new FileOutputStream(logDir + suite.getName() + ".xml")); } catch (FileNotFoundException e) { throw new ContainerException(e); } // per-suite results TestResult results = new TestResult(); results.addListener(new JunitListener()); results.addListener(xml); // add the suite to the xml listener xml.startTestSuite(test); // run the tests suite.run(results); test.setCounts(results.runCount(), results.failureCount(), results.errorCount()); // rollback all entity operations performed by the delegator testDelegator.rollback(); xml.endTestSuite(test); if (!results.wasSuccessful()) { failedRun = true; } // display the results Debug.logInfo("[JUNIT] Results for test suite: " + suite.getName(), module); Debug.logInfo("[JUNIT] Pass: " + results.wasSuccessful() + " | # Tests: " + results.runCount() + " | # Failed: " + results.failureCount() + " # Errors: " + results.errorCount(), module); if (Debug.importantOn() && !results.wasSuccessful()) { Debug.logInfo("[JUNIT] ----------------------------- ERRORS ----------------------------- [JUNIT]", module); Enumeration<?> err = results.errors(); if (!err.hasMoreElements()) { Debug.logInfo("None", module); } else { while (err.hasMoreElements()) { Object error = err.nextElement(); Debug.logInfo("--> " + error, module); if (error instanceof TestFailure) { Debug.logInfo(((TestFailure) error).trace(), module); } } } Debug.logInfo("[JUNIT] ------------------------------------------------------------------ [JUNIT]", module); Debug.logInfo("[JUNIT] ---------------------------- FAILURES ---------------------------- [JUNIT]", module); Enumeration<?> fail = results.failures(); if (!fail.hasMoreElements()) { Debug.logInfo("None", module); } else { while (fail.hasMoreElements()) { Object failure = fail.nextElement(); Debug.logInfo("--> " + failure, module); if (failure instanceof TestFailure) { Debug.logInfo(((TestFailure) failure).trace(), module); } } } Debug.logInfo("[JUNIT] ------------------------------------------------------------------ [JUNIT]", module); } } if (failedRun) { throw new ContainerException("Test run was unsuccessful"); } return true; }
Example 10
Source File: TestRunner.java From tomee with Apache License 2.0 | 4 votes |
/** * main entry point. */ public static void main(final String[] args) { if (args.length == 0) { printHelp(); } else { if (args[0].equals("--help")) { printHelp(); return; } else if (args[0].equals("local")) { runLocalTests(); } else if (args[0].equals("remote")) { runRemoteTests(); } else if (args[0].equals("http")) { runRemoteHttpTests(); } else if (args[0].equals("tomcat")) { runTomcatRemoteHttpTests(); } else { printHelp(); return; } try { final TestRunner aTestRunner = new TestRunner(); final TestResult r = aTestRunner.start(new String[]{"org.apache.openejb.test.ClientTestSuite"}); System.out.println(""); System.out.println("_________________________________________________"); System.out.println("CLIENT JNDI PROPERTIES"); final Properties env = TestManager.getServer().getContextEnvironment(); for (final Iterator iterator = env.entrySet().iterator(); iterator.hasNext(); ) { final Map.Entry entry = (Map.Entry) iterator.next(); final String key = (String) entry.getKey(); final Object value = entry.getValue(); System.out.println(key + " = " + value); } System.out.println("_________________________________________________"); if (!r.wasSuccessful()) System.exit(FAILURE_EXIT); System.exit(SUCCESS_EXIT); } catch (final Exception e) { System.err.println(e.getMessage()); System.exit(EXCEPTION_EXIT); } } }