hudson.tasks.junit.SuiteResult Java Examples

The following examples show how to use hudson.tasks.junit.SuiteResult. 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: TestResults.java    From github-autostatus-plugin with MIT License 6 votes vote down vote up
public static TestResults fromJUnitTestResults(@Nullable TestResultAction testResultAction) {

        if (testResultAction == null) {
            return null;
        }
        TestResults testResults = new TestResults();
        for (SuiteResult suiteResult : testResultAction.getResult().getSuites()) {
            TestSuite testSuite = new TestSuite();
            testSuite.setName(suiteResult.getName());
            testSuite.setDuration(suiteResult.getDuration());

            for (CaseResult caseResult : suiteResult.getCases()) {

                TestCase testCase = TestCase.fromCaseResult(caseResult);
                testResults.passedTestCaseCount += testCase.getPassedCount();
                testResults.skippedTestCaseCount += testCase.getSkippedCount();
                testResults.failedTestCaseCount += testCase.getFailedCount();
                testSuite.addTestCases(testCase);
            }
            testResults.testSuites.add(testSuite);
        }
        return testResults;
    }
 
Example #2
Source File: JUnitTestProvider.java    From phabricator-jenkins-plugin with MIT License 6 votes vote down vote up
/**
 * Convert JUnit's TestResult representation into a generic UnitResults
 *
 * @param jUnitResults The result of the JUnit run
 * @return The converted results
 */
public UnitResults convertJUnit(TestResult jUnitResults) {
    UnitResults results = new UnitResults();
    if (jUnitResults == null) {
        return results;
    }
    for (SuiteResult sr : jUnitResults.getSuites()) {
        for (CaseResult cr : sr.getCases()) {
            UnitResult result = new UnitResult(
                    cr.getClassName(),
                    cr.getDisplayName(),
                    cr.getErrorStackTrace(),
                    cr.getDuration(),
                    cr.getFailCount(),
                    cr.getSkipCount(),
                    cr.getPassCount()
            );
            results.add(result);
        }
    }
    return results;
}
 
Example #3
Source File: TestResultsTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void testfromJUnitTestResultsNotEmpty() {
    TestResultAction testResultAction = mock(TestResultAction.class);
    TestResult testResult = PowerMockito.mock(TestResult.class);
    SuiteResult suiteResult = PowerMockito.mock(SuiteResult.class);
    ArrayList<SuiteResult> suiteResults = new ArrayList<>();
    suiteResults.add(suiteResult);
    
    ArrayList<CaseResult> testCases = new ArrayList<>();
    CaseResult caseResult = mock(CaseResult.class);
    when(caseResult.isPassed()).thenReturn(true);
    when(caseResult.isFailed()).thenReturn(false);
    when(caseResult.isSkipped()).thenReturn(false);
    testCases.add(caseResult);
    when(suiteResult.getCases()).thenReturn(testCases);

    when(testResultAction.getResult()).thenReturn(testResult);
    when(testResult.getSuites()).thenReturn(suiteResults);
    
    TestResults instance = TestResults.fromJUnitTestResults(testResultAction);
    
    assertNotNull(instance);
    assertEquals(1, instance.getTestSuites().size());
    assertEquals(1, instance.getPassedTestCaseCount());
    assertEquals(0, instance.getSkippedTestCaseCount());
    assertEquals(0, instance.getFailedTestCaseCount());
}