public void startTestSuite(JUnitTest suite) { failures = 0; errors = 0; tests = 0; suiteName = suite.getName(); if (suiteName.lastIndexOf('.') > 0) { suiteName = suiteName.substring(suiteName.lastIndexOf('.')+1); } suiteName += "/"+System.getProperty("mithra.xml.config"); originalOut.println("Start Suite "+ suiteName); lastMessageTime = System.currentTimeMillis(); originalOut.flush(); flush(); }
@Override public void testFinished(Description description) throws Exception { System.out.flush(); System.err.flush(); System.setOut(oldStdout); System.setErr(oldStderr); formatter.setSystemOutput(stdout.toString()); formatter.setSystemError(stderr.toString()); formatter.endTest(new DescriptionAsTest(description)); JUnitTest suite = new JUnitTest(description.getDisplayName()); suite.setCounts(1,problem,0); suite.setRunTime(System.currentTimeMillis()-startTime); formatter.endTestSuite(suite); }
@Override public void endTestSuite(JUnitTest suite) throws BuildException { m_updateTimer.cancel(); m_updateTimer = null; if ((m_failures > 0) || (m_errs > 0)) { out.print("(FAIL-JUNIT) "); } else { out.print(" "); } synchronized (out) { out.flush(); out.printf("Tests run: %3d, Failures: %3d, Errors: %3d, Time elapsed: %.2f sec\n", m_tests, m_failures, m_errs, (System.currentTimeMillis() - m_start) / 1000.0); out.flush(); } }
/** * The whole testsuite started. * @param suite the test suite */ public void startTestSuite(JUnitTest suite) { if (output == null) { return; // Quick return - no output do nothing. } StringBuffer sb = new StringBuffer("Testsuite: "); String n = suite.getName(); if (n != null && !tag.isEmpty()) n = n + "-" + tag; sb.append(n); sb.append(StringUtils.LINE_SEP); try { output.write(sb.toString()); output.flush(); } catch (IOException ex) { throw new BuildException(ex); } }
/** * called when a test suite starts to run * @param suite a <code>JUnitTest</code> value */ public void startTestSuite(JUnitTest suite) { StringBuffer sb = new StringBuffer(); Object [] args = { "Running ", suite.getName() }; MessageFormat form = new MessageFormat("{0} {1}\n"); sb.append(form.format(args)); if (out != null) { try { out.write(sb.toString().getBytes()); out.flush(); } catch (IOException ioex) { throw new BuildException("Unable to write output", ioex); } // DO NOT CLOSE the out stream!!! } }
private void buildResultsMsg(JUnitTest suite, StringBuffer sb) { Object [] args = { suite.getName(), nf.format(suite.getRunTime() / RhnCustomFormatter.MS_PER_S), "ok" }; MessageFormat form = new MessageFormat("{0}({1}s): {2}\n\n"); long problemCount = suite.failureCount() + suite.errorCount(); if (problemCount > 0) { args[2] = problemCount + " NOT OK"; } sb.append(form.format(args)); }
@Override public void startTestSuite(JUnitTest suite) { if (output_ == null || suite.runCount()>0) { return; } if (suite.runCount()>0) { output_.println(); output_.println(); } output_.println("----------------------------------------------------------"); output_.println(suite.getName()); output_.println(); output_.flush(); count_total_ = 0; count_fail_ = 0; count_long_ = 0; }
@Override public void startTestSuite(JUnitTest suite) throws BuildException { m_currentSuite = suite; m_tests = m_errs = m_failures = 0; m_start = System.currentTimeMillis(); out.println("Running " + suite.getName()); }
@Override public void testStarted(Description description) throws Exception { formatter.startTestSuite(new JUnitTest(description.getDisplayName())); formatter.startTest(new DescriptionAsTest(description)); problem = 0; startTime = System.currentTimeMillis(); this.oldStdout = System.out; this.oldStderr = System.err; System.setOut(new PrintStream(stdout = new ByteArrayOutputStream())); System.setErr(new PrintStream(stderr = new ByteArrayOutputStream())); }
@Override public void startTestSuite(JUnitTest suite) throws BuildException { m_currentSuite = suite; m_tests = m_errs = m_failures = 0; m_start = System.currentTimeMillis(); out.println(" Running " + suite.getName()); // print a message to the console every few minutes so you know // roughly how long you've been running a test assert(m_updateTimer == null); DurationUpdater updateTask = new DurationUpdater(); m_updateTimer = new Timer("Duration Printer from JUnit Results Formatter"); int duration = DURATION_UPDATE_PERIOD_MIN * 60 * 1000; // ms m_updateTimer.schedule(updateTask, duration, duration); }
@Override public void startTestSuite(JUnitTest suite) throws BuildException { InitializingListener listener = new InitializingListener(); try { listener.testRunStarted(null); } catch (Exception e) { throw new BuildException("Failed to run EvoSuite initializing listener: "+e.getMessage(), e); } }
public void endTestSuite(JUnitTest suite) throws BuildException { for (File failure : failures) { try { copyFile(failure, new File(FAILED_TEST_RECORDINGS, failure.getName())); } catch (IOException e) { throw new BuildException("Cannot copy " + failure); } } }
/** * The whole testsuite started. * @param suite the testsuite. */ public void startTestSuite(final JUnitTest suite) { doc = getDocumentBuilder().newDocument(); rootElement = doc.createElement(TESTSUITE); String n = suite.getName(); // if (n != null && !tag.isEmpty()) // n = n + "-" + tag; rootElement.setAttribute(ATTR_NAME, n == null ? UNKNOWN : n); //add the timestamp final String timestamp = DateUtils.format(new Date(), DateUtils.ISO8601_DATETIME_PATTERN); rootElement.setAttribute(TIMESTAMP, timestamp); //and the hostname. rootElement.setAttribute(HOSTNAME, getHostname()); // Output properties final Element propsElement = doc.createElement(PROPERTIES); rootElement.appendChild(propsElement); final Properties props = suite.getProperties(); if (props != null) { final Enumeration e = props.propertyNames(); while (e.hasMoreElements()) { final String name = (String) e.nextElement(); final Element propElement = doc.createElement(PROPERTY); propElement.setAttribute(ATTR_NAME, name); propElement.setAttribute(ATTR_VALUE, props.getProperty(name)); propsElement.appendChild(propElement); } } }
/** * The whole testsuite ended. * @param suite the testsuite. * @throws BuildException on error. */ public void endTestSuite(final JUnitTest suite) throws BuildException { rootElement.setAttribute(ATTR_TESTS, "" + suite.runCount()); rootElement.setAttribute(ATTR_FAILURES, "" + suite.failureCount()); rootElement.setAttribute(ATTR_ERRORS, "" + suite.errorCount()); rootElement.setAttribute(ATTR_SKIPPED, "" + suite.skipCount()); rootElement.setAttribute( ATTR_TIME, "" + (suite.getRunTime() / ONE_SECOND)); if (out != null) { Writer wri = null; try { wri = new BufferedWriter(new OutputStreamWriter(out, "UTF8")); wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); (new DOMElementWriter()).write(rootElement, wri, 0, " "); } catch (final IOException exc) { throw new BuildException("Unable to write log file", exc); } finally { if (wri != null) { try { wri.flush(); } catch (final IOException ex) { // ignore } } if (out != System.out && out != System.err) { FileUtils.close(wri); } } } }
@Override public void startTestSuite(JUnitTest suite) throws BuildException { if (removedHandlers.size() != 0) { throw new IllegalStateException("removedHandlers must be empty"); } if (addedHandlers.size() != 0) { throw new IllegalStateException("addedHandlers must be empty"); } Logger root = Logger.getLogger(""); for (Handler handler : root.getHandlers()) { if (handler instanceof ConsoleHandler) { removedHandlers.add((ConsoleHandler) handler); } } for (ConsoleHandler oldHandler : removedHandlers) { ConsoleHandler newHandler = new ConsoleHandler(); newHandler.setLevel(oldHandler.getLevel()); newHandler.setFilter(oldHandler.getFilter()); newHandler.setFormatter(oldHandler.getFormatter()); try { newHandler.setEncoding(oldHandler.getEncoding()); } catch (UnsupportedEncodingException ex) { throw new IllegalStateException(ex); } newHandler.setErrorManager(oldHandler.getErrorManager()); root.addHandler(newHandler); addedHandlers.add(newHandler); root.removeHandler(oldHandler); } }
private void buildSummaryMsg(JUnitTest suite, StringBuffer sb) { Object [] args = { new Long(suite.runCount()), new Long(suite.failureCount()), new Long(suite.errorCount()), nf.format(suite.getRunTime() / RhnCustomFormatter.MS_PER_S) }; MessageFormat form = new MessageFormat( "Tests run: {0}, Failures: {1}, Errors: {2} Time elapsed: {3} sec\n"); sb.append(form.format(args)); }
/** * called when the test suite finishes running. * most of the interesting stuff happens here. * prints out the overall timing, and success, * or any failures that occur * @param suite a <code>JUnitTest</code> * @exception BuildException if an error occurs */ public void endTestSuite(JUnitTest suite) throws BuildException { StringBuffer sb = new StringBuffer(); buildSummaryMsg(suite, sb); buildResultsMsg(suite, sb); if (out != null) { try { out.write(sb.toString().getBytes()); out.flush(); } catch (IOException ioex) { throw new BuildException("Unable to write output", ioex); } finally { if (out != System.out && out != System.err) { try { out.close(); } catch (IOException ioex2) { System.out.println(ioex2); } } } } }
@Override protected void actOnTestResult(JUnitTask.TestResultHolder result, JUnitTest test, String name) { ++total; switch (result.exitCode) { case JUnitTaskMirror.JUnitTestRunnerMirror.SUCCESS: break; case JUnitTaskMirror.JUnitTestRunnerMirror.FAILURES: if (!failureTests.contains(test.getName())) { failureTests.add(test.getName()); } break; case JUnitTaskMirror.JUnitTestRunnerMirror.ERRORS: if (!errorTests.contains(test.getName())) { errorTests.add(test.getName()); } break; } if (result.timedOut) { if (!timedOutTests.contains(test.getName())) { timedOutTests.add(test.getName()); } } if (result.crashed) { if (!crashedTests.contains(test.getName())) { crashedTests.add(test.getName()); } } super.actOnTestResult(result, test, name); System.out.println(); System.out.println(); System.out.println(); }
/** * Helper function to create a suite that is initialized with the * suite name, start time, host data, and application URL. */ protected CMnDbTestSuite createSuiteData(JUnitTest suite) { CMnDbTestSuite result = new CMnDbTestSuite(CMnDbTestSuite.SuiteType.JUNIT); result.setStartTime(new Date()); result.setSuiteName(suite.getName()); result.setHostData(CMnDbHostData.getHostData()); // Load the database and host properties from the environment String appUrl = System.getProperty(MODELN_JDBC_URL); if ((appUrl != null) && (appUrl.length() > 0)) { result.setJdbcUrl(appUrl); } return result; }
/** * Return the name of the test suite. If the suite object does not * contain a value in the name field, the name will be derived from * the class name. * * @param suite Test suite information * @return Name of the test suite */ public String getSuiteName(JUnitTest suite) { String suiteName = null; String suiteClass = suite.getName(); String suitePackage = null; // If the suite name is not specified, use the class name instead if ((suite.getName() != null) && (suite.getName().length() > 0)) { int delimIdx = suite.getName().lastIndexOf('.'); if ((delimIdx > 0) && (delimIdx < suite.getName().length())) { suiteClass = suite.getName().substring(delimIdx); suitePackage = suite.getName().substring(0, delimIdx); } else { suitePackage = ""; } suiteName = suite.getName(); } else { suiteClass = suite.getClass().getName(); suitePackage = suite.getClass().getPackage().getName(); // Trim off the fully qualified package name if ((suitePackage != null) && suiteClass.startsWith(suitePackage) && (suiteClass.length() > suitePackage.length())) { suiteName = suite.getName().substring(suitePackage.length() + 1); } else { suiteName = suite.getName(); } } return suiteName; }
@Override public void endTestSuite(JUnitTest suite) { if (output_ == null) { return; } try { if (count_fail_==0) { output_.println(); if (count_long_>0) { output_.print("TOO LONG: "); output_.print(count_long_); output_.print(" / "); output_.print(count_total_); } else if (count_total_>0) { output_.print("SUCCESS: "); output_.print(count_total_); } } output_.println(); output_.flush(); } finally { if (out_ != System.out && out_ != System.err) { try { out_.close(); } catch (IOException ex) { ex.printStackTrace(); } } } }
@Override public void endTestSuite(JUnitTest suite) throws BuildException { out.printf("Tests run: %3d, Failures: %3d, Errors: %3d, Time elapsed: %.2f sec\n", m_tests, m_failures, m_errs, (System.currentTimeMillis() - m_start) / 1000.0); }
@Override public void startTestSuite(JUnitTest suite) { startTimes.put(suite.getName(), System.currentTimeMillis()); super.startTestSuite(suite); }
@Override public void endTestSuite(JUnitTest suite) throws BuildException { long startTime = startTimes.get(suite.getName()); suite.setRunTime((System.currentTimeMillis() - startTime)); super.endTestSuite(suite); }
public void endTestSuite(JUnitTest suite) throws BuildException { originalOut.println("End Suite "+suiteName+" Tests: "+tests+" Failures: "+failures+" Errors: "+errors); flush(); }
public void startTestSuite(JUnitTest suite) throws BuildException { currentSuit = suite.getName(); failures.clear(); }
public PDETestListener(Object collector, String suite) { resultsCollector = collector; suiteName = suite; junitTestSuite = new JUnitTest(suiteName); junitTestSuite.setProperties(System.getProperties()); }
public void endTestSuite(JUnitTest suite) { String newLine = System.getProperty("line.separator"); StringBuffer sb = new StringBuffer(); if (build != null) { sb.append("Build Version: " + build.getBuildVersion() + newLine); } sb.append("Testsuite: " + suite.getName() + newLine); sb.append("Tests run: " + suite.runCount()); sb.append(", Failures: " + suite.failureCount()); sb.append(", Errors: " + suite.errorCount()); sb.append(", Time elapsed: " + nf.format(suite.getRunTime() / 1000.0) + " sec"); sb.append(newLine); // append the err and output streams to the log if (systemOutput != null && systemOutput.length() > 0) { sb.append("------------- Standard Output ---------------") .append(newLine) .append(systemOutput) .append("------------- ---------------- ---------------") .append(newLine); } if (systemError != null && systemError.length() > 0) { sb.append("------------- Standard Error -----------------") .append(newLine) .append(systemError) .append("------------- ---------------- ---------------") .append(newLine); } sb.append(newLine); if (out != null) { try { out.write(sb.toString().getBytes()); wri.close(); out.write(inner.toString().getBytes()); out.flush(); } catch (IOException ioex) { throw new BuildException("Unable to write output", ioex); } finally { if (out != System.out && out != System.err) { try { out.close(); } catch (IOException e) { // ignore } } } } // Update the date in the database if (conn != null) { try { Date enddate = new Date(); CMnUnittestTable.getInstance().setSuiteEndDate(conn, suiteId, enddate); suiteData.setEndTime(enddate); } catch (SQLException ex) { throw new BuildException("Unable to add suite information to the database.", ex); } } else { throw new BuildException("Database connection unavailable."); } }