/** * Get the test set starting message for a report. eg. "Running org.foo.BarTest ( of group )" * * @param report report whose test set is starting * @return the message */ static String getTestSetStartingMessage(ReportEntry report) { StringBuilder message = new StringBuilder(); message.append(TEST_SET_STARTING_PREFIX); message.append(report.getNameWithGroup()); message.append("\n"); return message.toString(); }
// Mostly taken from Junit4Provider.java public RunResult invokeJunit4(Class<?> clazz, String requestedTestMethod) throws TestSetFailedException { final ReporterFactory reporterFactory = providerParameters.getReporterFactory(); RunListener reporter = reporterFactory.createReporter(); ConsoleOutputCapture.startCapture((ConsoleOutputReceiver) reporter); JUnit4RunListener jUnit4TestSetReporter = new JUnit4RunListener(reporter); Result result = new Result(); RunNotifier listeners = getRunNotifier(jUnit4TestSetReporter, result, customRunListeners); listeners.fireTestRunStarted(Description.createTestDescription(clazz, requestedTestMethod)); final ReportEntry report = new SimpleReportEntry( getClass().getName() + "." + requestedTestMethod, clazz.getName() + "." + requestedTestMethod); reporter.testSetStarting(report); try { for (final Method method : clazz.getMethods()) { if (method.getParameterTypes().length == 0 && requestedTestMethod.equals(method.getName())) { Request.method(clazz, method.getName()).getRunner().run(listeners); } } } catch (Throwable e) { reporter.testError( SimpleReportEntry.withException( report.getSourceName(), report.getName(), new PojoStackTraceWriter(report.getSourceName(), report.getName(), e))); } finally { reporter.testSetCompleted(report); } listeners.fireTestRunFinished(result); JUnit4RunListener.rethrowAnyTestMechanismFailures(result); closeRunNotifier(jUnit4TestSetReporter, customRunListeners); return reporterFactory.close(); }
private PrintWriter testSetStarting(ReportEntry report) { File reportFile = getReportFile(reportsDirectory, report.getName(), reportNameSuffix, ".txt"); File reportDir = reportFile.getParentFile(); // noinspection ResultOfMethodCallIgnored reportDir.mkdirs(); try { PrintWriter writer = new PrintWriter(new FileWriter(reportFile)); writer.println( "-------------------------------------------------------------------------------"); writer.println("Test set: " + report.getName()); writer.println( "-------------------------------------------------------------------------------"); return writer; } catch (IOException e) { throw new ReporterException("Unable to create file for report: " + e.getMessage(), e); } }
public RunEntryStatistics createNextGeneration(ReportEntry reportEntry) { final RunEntryStatistics newItem = findOrCreate(reportEntry); final Integer elapsed = reportEntry.getElapsed(); return newItem.nextGeneration(elapsed != null ? elapsed.intValue() : 0); }
public RunEntryStatistics findOrCreate(ReportEntry reportEntry) { final RunEntryStatistics item = (RunEntryStatistics) runEntryStatistics.get(reportEntry.getName()); return item != null ? item : RunEntryStatistics.fromReportEntry(reportEntry); }