类org.apache.maven.plugins.surefire.report.SurefireReportParser源码实例Demo

下面列出了怎么用org.apache.maven.plugins.surefire.report.SurefireReportParser的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: repairnator   文件: AbstractRepairMojo.java
public List<String> getFailingTests() {
    List<String> result = new ArrayList<>();

    for (MavenProject mavenProject : reactorProjects) {
        File surefireReportsDirectory = getSurefireReportsDirectory(mavenProject);
        SurefireReportParser parser = new SurefireReportParser(Collections.singletonList(surefireReportsDirectory), Locale.ENGLISH, new NullConsoleLogger());

        try {
            List<ReportTestSuite> testSuites = parser.parseXMLReportFiles();
            for (ReportTestSuite reportTestSuite : testSuites) {
                if (reportTestSuite.getNumberOfErrors()+reportTestSuite.getNumberOfFailures() > 0) {
                    result.add(reportTestSuite.getFullClassName());
                }
            }
        } catch (MavenReportException e) {
            e.printStackTrace();;
        }

    }

    return result;
}
 
源代码2 项目: testgrid   文件: SurefireReporter.java
/**
 * Parses the surefire reports and returns a summarized TestResult object.
 *
 * @param testPlan the testplan
 * @return test result
 */
public TestResult getReport(TestPlan testPlan) {
    TestResult testResult = new TestResult();
    try {
        Path filePath = TestGridUtil.getSurefireReportsDir(testPlan);
        final SurefireReportParser surefireReportParser = new SurefireReportParser(
                Collections.singletonList(filePath.toFile()),
                ENGLISH,
                new NullConsoleLogger());
        final List<ReportTestSuite> reportTestSuites = surefireReportParser.parseXMLReportFiles();
        final Map<String, String> summary = surefireReportParser.getSummary(reportTestSuites);
        testResult.totalTests = summary.get("totalTests");
        testResult.totalFailures = summary.get("totalFailures");
        testResult.totalErrors = summary.get("totalErrors");
        testResult.totalSkipped = summary.get("totalSkipped");

        final List<ReportTestCase> failureDetails = surefireReportParser.getFailureDetails(reportTestSuites);
        testResult.failureTests = getTests(failureDetails, ReportTestCase::hasFailure);
        testResult.errorTests = getTests(failureDetails, ReportTestCase::hasError);

        return testResult;
    } catch (MavenReportException e) {
        logger.warn("Error while processing surefire-reports for " + testPlan.getId() + " for infra combination:"
                + " " + testPlan.getInfraParameters() + ". Continuing processing of other test plans", e);
    }

    return testResult;
}
 
源代码3 项目: wisdom   文件: UnitTestMojo.java
/**
 * Notifies the watcher that a new file is created. It selects and executes the test. Failures and errors are
 * reported in the thrown {@link org.wisdom.maven.WatchingException}.
 *
 * @param file is the file.
 * @return return {@code true}
 * @throws org.wisdom.maven.WatchingException if the test execution failed.
 */
@Override
public boolean fileCreated(File file) throws WatchingException {
    // Check selection policy
    String testParameter = null;
    if (testSelectionPolicy == TestSelectionPolicy.SELECTIVE) {
        // The test selection is done using the -Dtest parameter from surefire
        // We should also take care that the changed file is not a 'test', in that case, we run only this one.
        final String filename = file.getName().substring(0, file.getName().lastIndexOf("."));
        if (filename.startsWith("Test")  || filename.endsWith("Test")  || filename.endsWith("TestCase")) {
            testParameter = filename;
        } else {
            // It's a business class
            // Be aware of #365, the selection must select only unit tests, so the expression should be
            // TestFileName*,*FileNameTest*
            // The *FileNameTestCase case can be ignored (included by the second expression)
            testParameter = "Test" + filename + "*,*" + filename + "Test*";
        }
    }

    try {
        execute(testParameter);
        return true;
    } catch (MojoExecutionException e) {
        getLog().debug("An error occurred while executing Surefire", e);
        // Compute the Watching Exception content.
        StringBuilder message = new StringBuilder();
        SurefireReportParser parser = new SurefireReportParser(ImmutableList.of(reports), Locale.ENGLISH);
        try {
            computeTestFailureMessageFromReports(message, parser);
            throw new WatchingException("Unit Test Failures", message.toString(), file, e);
        } catch (MavenReportException reportException) {
            // Cannot read the reports.
            throw new WatchingException("Unit Test Failures", file, reportException);
        }}
}
 
源代码4 项目: 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>");
}
 
 类所在包
 类方法