Java 类org.apache.maven.plugins.surefire.report.ReportTestCase 实例源码

项目:h2spec-maven-plugin    文件:H2SpecTestSuite.java   
private static List<Failure> parseReports(final File reportsDirectory, final Set<String> excludeSpecs) {
    SurefireReportParser parser = new SurefireReportParser(Collections.singletonList(reportsDirectory), Locale.getDefault());

    String currentPackageName = "";
    List<Failure> failures = new ArrayList<Failure>();
    try {
        List<ReportTestSuite> parsedReports = parser.parseXMLReportFiles();
        for (ReportTestSuite parsedReport : parsedReports) {
            String packageName = parsedReport.getPackageName();
            if (packageName.length() > 0) {
                currentPackageName = packageName;
            }

            if (parsedReport.getNumberOfErrors() > 0) {
                for (ReportTestCase reportTestCase : parsedReport.getTestCases()) {
                    String name = parsedReport.getFullClassName();
                    boolean ignored = excludeSpecs.contains(getSpecIdentifier(currentPackageName, name));
                    String failureDetail = reportTestCase.getFailureDetail();
                    String[] failureTokens = failureDetail.split("\n");

                    String expected = failureTokens.length > 0 ? failureTokens[0] : "";
                    String actual = failureTokens.length > 1 ? failureTokens[1] : "";
                    failures.add(new Failure(name, currentPackageName, actual, expected, ignored));
                }
            }
        }

    } catch (MavenReportException e) {
        e.printStackTrace();
    }

    return failures;
}
项目:NonDex    文件:CleanSurefireExecution.java   
public void run() throws MojoExecutionException {
    try {
        Xpp3Dom domNode = this.applyNonDexConfig((Xpp3Dom) this.surefire.getConfiguration());
        this.setupArgline(domNode);
        Logger.getGlobal().log(Level.FINE, "Config node passed: " + domNode.toString());
        Logger.getGlobal().log(Level.FINE, this.mavenProject + "\n" + this.mavenSession + "\n" + this.pluginManager);
        Logger.getGlobal().log(Level.CONFIG, this.configuration.toString());
        Logger.getGlobal().log(Level.FINE, "Surefire config: " + this.surefire + "  " + MojoExecutor.goal("test")
                               + " " + domNode + " "
                               + MojoExecutor.executionEnvironment(this.mavenProject, this.mavenSession,
                                                                   this.pluginManager));
        MojoExecutor.executeMojo(this.surefire, MojoExecutor.goal("test"),
                domNode,
                MojoExecutor.executionEnvironment(this.mavenProject, this.mavenSession, this.pluginManager));
    } catch (MojoExecutionException mojoException) {
        Logger.getGlobal().log(Level.INFO, "Surefire failed when running tests for " + this.configuration.executionId);

        SurefireReportParser parser = new SurefireReportParser(
                Arrays.asList(this.configuration.getExecutionDir().toFile()), Locale.getDefault());
        try {
            Set<String> failingTests = new LinkedHashSet<>();
            for (ReportTestSuite report : parser.parseXMLReportFiles()) {
                for (ReportTestCase testCase : report.getTestCases()) {
                    // Record if failed, but not skipped
                    if (testCase.hasFailure() && !"skipped".equals(testCase.getFailureType())) {
                        failingTests.add(testCase.getFullClassName() + '#' + testCase.getName());
                    }
                }
            }
            this.configuration.setFailures(failingTests);
        } catch (MavenReportException ex) {
            throw new MojoExecutionException("Failed to parse mvn reports!");
        }
        throw mojoException;
    } catch (Throwable tr) {
        Logger.getGlobal().log(Level.SEVERE, "Some exception that is highly unexpected: ", tr);
        throw tr;
    }
}
项目:wisdom    文件:UnitTestMojo.java   
private static void computeTestFailureMessageFromReports(StringBuilder message, SurefireReportParser parser)
        throws MavenReportException {
    List<ReportTestSuite> suites = parser.parseXMLReportFiles();
    Map<String, String> summary = parser.getSummary(suites);
    message
            .append(summary.get("totalTests"))
            .append(" tests, ")
            .append(summary.get("totalErrors"))
            .append(" errors, ")
            .append(summary.get("totalFailures"))
            .append(" failures, ")
            .append(summary.get("totalSkipped"))
            .append(" skipped ")
            .append("(executed in ")
            .append(summary.get("totalElapsedTime"))
            .append("s)<br/><ul>");
    for (ReportTestSuite suite : suites) {
        if (suite.getNumberOfErrors() > 0 || suite.getNumberOfFailures() > 0) {
            for (ReportTestCase tc : suite.getTestCases()) {
                if (tc.getFailure() != null
                        && !"skipped".equalsIgnoreCase((String) tc.getFailure().get("message"))) {
                    message
                            .append("<li><em>")
                            .append(tc.getFullName())
                            .append("</em> failed: ")
                            .append(tc.getFailure().get("message"))
                            .append("</li>");
                }
            }
        }
    }
    message.append("</ul>");
}