Java Code Examples for junit.framework.TestResult#addListener()
The following examples show how to use
junit.framework.TestResult#addListener() .
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: JUnitServlet.java From lams with GNU General Public License v2.0 | 5 votes |
void runTestSuite( String testClassName ) { Test suite = getTest( testClassName ); if (suite != null) { TestResult testResult = new TestResult(); testResult.addListener( this ); long startTime= System.currentTimeMillis(); suite.run( testResult ); long endTime= System.currentTimeMillis(); _formatter.displayResults( _writer, testClassName, elapsedTimeAsString( endTime-startTime ), testResult ); } }
Example 2
Source File: TestListenerTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
protected void setUp() { fResult= new TestResult(); fResult.addListener(this); fStartCount= 0; fEndCount= 0; fFailureCount= 0; }
Example 3
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 4
Source File: JUnit38ClassRunner.java From android-test with Apache License 2.0 | 4 votes |
@Override public void run(RunNotifier notifier) { TestResult result = new TestResult(); result.addListener(createAdaptingListener(notifier)); getTest().run(result); }
Example 5
Source File: MyUiAutomatorTestRunner.java From PUMA with Apache License 2.0 | 4 votes |
/** * Called after all test classes are in place, ready to test */ protected void start() { TestCaseCollector collector = getTestCaseCollector(this.getClass().getClassLoader()); try { collector.addTestClasses(mTestClasses); } catch (ClassNotFoundException e) { // will be caught by uncaught handler throw new RuntimeException(e.getMessage(), e); } if (mDebug) { Debug.waitForDebugger(); } mHandlerThread = new HandlerThread(HANDLER_THREAD_NAME); mHandlerThread.setDaemon(true); mHandlerThread.start(); UiAutomationShellWrapper automationWrapper = new UiAutomationShellWrapper(); automationWrapper.connect(); long startTime = SystemClock.uptimeMillis(); TestResult testRunResult = new TestResult(); ResultReporter resultPrinter; String outputFormat = mParams.getString("outputFormat"); List<TestCase> testCases = collector.getTestCases(); Bundle testRunOutput = new Bundle(); if ("simple".equals(outputFormat)) { resultPrinter = new SimpleResultPrinter(System.out, true); } else { resultPrinter = new WatcherResultPrinter(testCases.size()); } try { automationWrapper.setRunAsMonkey(mMonkey); mUiDevice = MyUiDevice.getInstance(); UiAutomation uiAutomation = automationWrapper.getUiAutomation(); mUiDevice.initialize(new ShellUiAutomatorBridge(uiAutomation)); mUiDevice.setUiAutomation(uiAutomation); String traceType = mParams.getString("traceOutputMode"); if (traceType != null) { Tracer.Mode mode = Tracer.Mode.valueOf(Tracer.Mode.class, traceType); if (mode == Tracer.Mode.FILE || mode == Tracer.Mode.ALL) { String filename = mParams.getString("traceLogFilename"); if (filename == null) { throw new RuntimeException("Name of log file not specified. " + "Please specify it using traceLogFilename parameter"); } Tracer.getInstance().setOutputFilename(filename); } Tracer.getInstance().setOutputMode(mode); } // add test listeners testRunResult.addListener(resultPrinter); // add all custom listeners for (TestListener listener : mTestListeners) { testRunResult.addListener(listener); } // run tests for realz! for (TestCase testCase : testCases) { prepareTestCase(testCase); testCase.run(testRunResult); } } catch (Throwable t) { // catch all exceptions so a more verbose error message can be outputted resultPrinter.printUnexpectedError(t); } finally { long runTime = SystemClock.uptimeMillis() - startTime; resultPrinter.print(testRunResult, runTime, testRunOutput); automationWrapper.disconnect(); automationWrapper.setRunAsMonkey(false); mHandlerThread.quit(); } }