hudson.tasks.junit.CaseResult Java Examples

The following examples show how to use hudson.tasks.junit.CaseResult. 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: DeflakeListenerTest.java    From flaky-test-handler-plugin with Apache License 2.0 6 votes vote down vote up
static List<CaseResult> setupCaseResultList() {
  CaseResult caseOne = mock(CaseResult.class);
  CaseResult caseTwo = mock(CaseResult.class);
  CaseResult caseThree = mock(CaseResult.class);

  when(caseOne.getClassName()).thenReturn(TEST_CLASS_ONE);
  when(caseOne.getName()).thenReturn(TEST_METHOD_ONE);

  when(caseTwo.getClassName()).thenReturn(TEST_CLASS_ONE);
  when(caseTwo.getName()).thenReturn(TEST_METHOD_TWO);

  when(caseThree.getClassName()).thenReturn(TEST_CLASS_TWO);
  when(caseThree.getName()).thenReturn(TEST_METHOD_ONE);

  List<CaseResult> caseResultList = new ArrayList<CaseResult>();
  caseResultList.add(caseOne);
  caseResultList.add(caseTwo);
  caseResultList.add(caseThree);
  return caseResultList;
}
 
Example #3
Source File: JUnitResultsStepTest.java    From junit-plugin with MIT License 6 votes vote down vote up
@Test
public void singleStep() throws Exception {
    WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "singleStep");
    j.setDefinition(new CpsFlowDefinition("stage('first') {\n" +
            "  node {\n" +
            "    def results = junit(testResults: '*.xml')\n" + // node id 7
            "    assert results.totalCount == 6\n" +
            "  }\n" +
            "}\n", true));
    FilePath ws = rule.jenkins.getWorkspaceFor(j);
    FilePath testFile = ws.child("test-result.xml");
    testFile.copyFrom(TestResultTest.class.getResource("junit-report-1463.xml"));

    WorkflowRun r = rule.buildAndAssertSuccess(j);
    TestResultAction action = r.getAction(TestResultAction.class);
    assertNotNull(action);
    assertEquals(1, action.getResult().getSuites().size());
    assertEquals(6, action.getTotalCount());

    assertExpectedResults(r, 1, 6, "7");

    // Case result display names shouldn't include stage, since there's only one stage.
    for (CaseResult c : action.getPassedTests()) {
        assertEquals(c.getTransformedTestName(), c.getDisplayName());
    }
}
 
Example #4
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 #5
Source File: TestCase.java    From github-autostatus-plugin with MIT License 6 votes vote down vote up
public static TestCase fromCaseResult(CaseResult caseResult) {
    TestCase testCase = new TestCase();

    if (caseResult.isPassed()) {
        testCase.setPassed(true);
    }
    if (caseResult.isSkipped()) {
        testCase.setSkipped(true);
    }
    if (caseResult.isFailed()) {
        testCase.setFailed(true);
    }
    testCase.setName(caseResult.getFullName());
    return testCase;

}
 
Example #6
Source File: TestCaseTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void testInitialPassedTrue() {
    CaseResult caseResult = mock(CaseResult.class);
    when(caseResult.isPassed()).thenReturn(true);
    TestCase result = TestCase.fromCaseResult(caseResult);
    assertTrue(result.isPassed());
    assertEquals(result.getResult(), TestCase.TestCaseResult.Passed);
}
 
Example #7
Source File: DeflakeListenerTest.java    From flaky-test-handler-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetFailingTestClassMethodMapWithNoTest() {
  assertTrue("Should return empty map for empty input list",
      DeflakeListener.getFailingTestClassMethodMap(new ArrayList<CaseResult>()).isEmpty());
  assertTrue("Should return empty map for null input list",
      DeflakeListener.getFailingTestClassMethodMap(null).isEmpty());
}
 
Example #8
Source File: DeflakeListenerTest.java    From flaky-test-handler-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetFailingTestClassMethodMap() throws Exception {
  List<CaseResult> caseResultList = setupCaseResultList();
  Map<String, Set<String>> classMethodMap = DeflakeListener.getFailingTestClassMethodMap(
      caseResultList);
  assertEquals("Map size should be equal to number of classes", 2, classMethodMap.size());
  Set<String> expectedClassOneMethods = Sets.newHashSet(TEST_METHOD_ONE, TEST_METHOD_TWO);
  Set<String> expectedClassTwoMethods = Sets.newHashSet(TEST_METHOD_ONE);

  assertEquals("Incorrect test methods", expectedClassOneMethods,
      classMethodMap.get(TEST_CLASS_ONE));
  assertEquals("Incorrect test methods", expectedClassTwoMethods,
      classMethodMap.get(TEST_CLASS_TWO));
}
 
Example #9
Source File: DeflakeListener.java    From flaky-test-handler-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Organize failing test cases by their class names
 *
 * @param caseResultList all the failing test cases list
 * @return the map with class name and the set of test methods in each class
 */
static Map<String, Set<String>> getFailingTestClassMethodMap(List<CaseResult> caseResultList) {
  Map<String, Set<String>> classMethodMap = new HashMap<String, Set<String>>();
  if (caseResultList != null) {
    for (CaseResult caseResult : caseResultList) {
      if (!classMethodMap.containsKey(caseResult.getClassName())) {
        classMethodMap.put(caseResult.getClassName(), new HashSet<String>());
      }
      classMethodMap.get(caseResult.getClassName()).add(caseResult.getName());
    }
  }
  return classMethodMap;
}
 
Example #10
Source File: JUnitResultsStepTest.java    From junit-plugin with MIT License 5 votes vote down vote up
public static void assertBranchResults(WorkflowRun run, int suiteCount, int testCount, int failCount, String branchName, String stageName,
                                       String innerStageName) {
    FlowExecution execution = run.getExecution();
    DepthFirstScanner scanner = new DepthFirstScanner();
    BlockStartNode aBranch = (BlockStartNode)scanner.findFirstMatch(execution, branchForName(branchName));
    assertNotNull(aBranch);
    TestResult branchResult = assertBlockResults(run, suiteCount, testCount, failCount, aBranch);
    String namePrefix = stageName + " / " + branchName;
    if (innerStageName != null) {
        namePrefix += " / " + innerStageName;
    }
    for (CaseResult c : branchResult.getPassedTests()) {
        assertEquals(namePrefix + " / " + c.getTransformedTestName(), c.getDisplayName());
    }
}
 
Example #11
Source File: JUnitResultsStepTest.java    From junit-plugin with MIT License 5 votes vote down vote up
@Test
public void twoSteps() throws Exception {
    WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "twoSteps");
    j.setDefinition(new CpsFlowDefinition("stage('first') {\n" +
            "  node {\n" +
            "    def first = junit(testResults: 'first-result.xml')\n" +    // node id 7
            "    def second = junit(testResults: 'second-result.xml')\n" +  // node id 8
            "    assert first.totalCount == 6\n" +
            "    assert second.totalCount == 1\n" +
            "  }\n" +
            "}\n", true));
    FilePath ws = rule.jenkins.getWorkspaceFor(j);
    FilePath testFile = ws.child("first-result.xml");
    testFile.copyFrom(TestResultTest.class.getResource("junit-report-1463.xml"));
    FilePath secondTestFile = ws.child("second-result.xml");
    secondTestFile.copyFrom(TestResultTest.class.getResource("junit-report-2874.xml"));

    WorkflowRun r = rule.buildAndAssertSuccess(j);
    TestResultAction action = r.getAction(TestResultAction.class);
    assertNotNull(action);
    assertEquals(2, action.getResult().getSuites().size());
    assertEquals(7, action.getTotalCount());

    // First call
    assertExpectedResults(r, 1, 6, "7");

    // Second call
    assertExpectedResults(r, 1, 1, "8");

    // Combined calls
    assertExpectedResults(r, 2, 7, "7", "8");

    // Case result display names shouldn't include stage, since there's only one stage.
    for (CaseResult c : action.getPassedTests()) {
        assertEquals(c.getTransformedTestName(), c.getDisplayName());
    }
}
 
Example #12
Source File: TestCaseTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void testInitialPassedFalse() {
    CaseResult caseResult = mock(CaseResult.class);
    when(caseResult.isPassed()).thenReturn(false);
    TestCase result = TestCase.fromCaseResult(caseResult);
    assertFalse(result.isPassed());
    assertNull(result.getResult());
}
 
Example #13
Source File: TestCaseTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void testInitialName() {
    String testName = "mock-name";
    CaseResult caseResult = mock(CaseResult.class);
    when(caseResult.getFullName()).thenReturn(testName);
    TestCase result = TestCase.fromCaseResult(caseResult);
    assertEquals(testName, result.getName());
    assertNull(result.getResult());
}
 
Example #14
Source File: BlueJUnitTestResult.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Override
public Result getBlueTestResults(Run<?, ?> run, final Reachable parent) {
    TestResultAction action = run.getAction(TestResultAction.class);
    if (action == null) {
        return Result.notFound();
    }
    List<CaseResult> testsToTransform = new ArrayList<>();
    testsToTransform.addAll(action.getFailedTests());
    testsToTransform.addAll(action.getSkippedTests());
    testsToTransform.addAll(action.getPassedTests());
    return Result.of(Iterables.transform(testsToTransform, //
                                         input ->  new BlueJUnitTestResult(input, parent.getLink())));
}
 
Example #15
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());
}
 
Example #16
Source File: TestCaseTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void testInitialFailedFalse() {
    CaseResult caseResult = mock(CaseResult.class);
    when(caseResult.isFailed()).thenReturn(false);
    TestCase result = TestCase.fromCaseResult(caseResult);
    assertFalse(result.isFailed());
    assertNull(result.getResult());
}
 
Example #17
Source File: TestCaseTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void testInitialFailedTrue() {
    CaseResult caseResult = mock(CaseResult.class);
    when(caseResult.isFailed()).thenReturn(true);
    TestCase result = TestCase.fromCaseResult(caseResult);
    assertTrue(result.isFailed());
    assertEquals(result.getResult(), TestCase.TestCaseResult.Failed);
}
 
Example #18
Source File: TestCaseTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void testInitialSkippedFalse() {
    CaseResult caseResult = mock(CaseResult.class);
    when(caseResult.isSkipped()).thenReturn(false);
    TestCase result = TestCase.fromCaseResult(caseResult);
    assertFalse(result.isSkipped());
    assertNull(result.getResult());
}
 
Example #19
Source File: TestCaseTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void testInitialSkippedTrue() {
    CaseResult caseResult = mock(CaseResult.class);
    when(caseResult.isSkipped()).thenReturn(true);
    TestCase result = TestCase.fromCaseResult(caseResult);
    assertTrue(result.isSkipped());
    assertEquals(result.getResult(), TestCase.TestCaseResult.Skipped);
}
 
Example #20
Source File: BlueJUnitTestResult.java    From blueocean-plugin with MIT License 4 votes vote down vote up
public BlueJUnitTestResult(CaseResult testResult, Link parent) {
    super(parent);
    this.testResult = testResult;
}
 
Example #21
Source File: JUnitResultsStepTest.java    From junit-plugin with MIT License 4 votes vote down vote up
@Test
public void threeSteps() throws Exception {
    WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "threeSteps");
    j.setDefinition(new CpsFlowDefinition("stage('first') {\n" +
            "  node {\n" +
            "    def first = junit(testResults: 'first-result.xml')\n" +    // node id 7
            "    def second = junit(testResults: 'second-result.xml')\n" +  // node id 8
            "    def third = junit(testResults: 'third-result.xml')\n" +    // node id 9
            "    assert first.totalCount == 6\n" +
            "    assert second.totalCount == 1\n" +
            "  }\n" +
            "}\n", true));
    FilePath ws = rule.jenkins.getWorkspaceFor(j);
    FilePath testFile = ws.child("first-result.xml");
    testFile.copyFrom(TestResultTest.class.getResource("junit-report-1463.xml"));
    FilePath secondTestFile = ws.child("second-result.xml");
    secondTestFile.copyFrom(TestResultTest.class.getResource("junit-report-2874.xml"));
    FilePath thirdTestFile = ws.child("third-result.xml");
    thirdTestFile.copyFrom(TestResultTest.class.getResource("junit-report-nested-testsuites.xml"));

    WorkflowRun r = rule.assertBuildStatus(Result.UNSTABLE,
            rule.waitForCompletion(j.scheduleBuild2(0).waitForStart()));
    TestResultAction action = r.getAction(TestResultAction.class);
    assertNotNull(action);
    assertEquals(5, action.getResult().getSuites().size());
    assertEquals(10, action.getTotalCount());

    // First call
    assertExpectedResults(r, 1, 6, "7");

    // Second call
    assertExpectedResults(r, 1, 1, "8");

    // Third call
    assertExpectedResults(r, 3, 3, "9");

    // Combined first and second calls
    assertExpectedResults(r, 2, 7, "7", "8");

    // Combined first and third calls
    assertExpectedResults(r, 4, 9, "7", "9");

    // Case result display names shouldn't include stage, since there's only one stage.
    for (CaseResult c : action.getPassedTests()) {
        assertEquals(c.getTransformedTestName(), c.getDisplayName());
    }
}
 
Example #22
Source File: JUnitResultsStepTest.java    From junit-plugin with MIT License 4 votes vote down vote up
@Test
public void testTrends() throws Exception {
    WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "testTrends");
    j.setDefinition(new CpsFlowDefinition("node {\n" +
            "  stage('first') {\n" +
            "    def first = junit(testResults: \"junit-report-testTrends-first.xml\")\n" +
            "  }\n" +
            "  stage('second') {\n" +
            "    def second = junit(testResults: \"junit-report-testTrends-second.xml\")\n" +
            "  }\n" +
            "}\n", true));
    FilePath ws = rule.jenkins.getWorkspaceFor(j);
    FilePath firstFile = ws.child("junit-report-testTrends-first.xml");
    FilePath secondFile = ws.child("junit-report-testTrends-second.xml");

    // Populate first run's tests.
    firstFile.copyFrom(JUnitResultsStepTest.class.getResource("junit-report-testTrends-first-1.xml"));
    secondFile.copyFrom(JUnitResultsStepTest.class.getResource("junit-report-testTrends-second-1.xml"));

    WorkflowRun firstRun = rule.buildAndAssertSuccess(j);
    assertStageResults(firstRun, 1, 8, 0, "first");
    assertStageResults(firstRun, 1, 1, 0, "second");

    // Populate second run's tests.
    firstFile.copyFrom(JUnitResultsStepTest.class.getResource("junit-report-testTrends-first-2.xml"));
    secondFile.copyFrom(JUnitResultsStepTest.class.getResource("junit-report-testTrends-second-2.xml"));

    WorkflowRun secondRun = rule.assertBuildStatus(Result.UNSTABLE, rule.waitForCompletion(j.scheduleBuild2(0).waitForStart()));
    assertStageResults(secondRun, 1, 8, 3, "first");
    assertStageResults(secondRun, 1, 1, 0, "second");

    // Populate third run's tests
    firstFile.copyFrom(JUnitResultsStepTest.class.getResource("junit-report-testTrends-first-3.xml"));
    secondFile.copyFrom(JUnitResultsStepTest.class.getResource("junit-report-testTrends-second-3.xml"));

    WorkflowRun thirdRun = rule.assertBuildStatus(Result.UNSTABLE, rule.waitForCompletion(j.scheduleBuild2(0).waitForStart()));
    assertStageResults(thirdRun, 1, 8, 3, "first");
    assertStageResults(thirdRun, 1, 1, 0, "second");
    TestResultAction thirdAction = thirdRun.getAction(TestResultAction.class);
    assertNotNull(thirdAction);

    for (CaseResult failed : thirdAction.getFailedTests()) {
        if (failed.getDisplayName() != null) {
            if (failed.getDisplayName().equals("first / testGetVendorFirmKeyForVendorRep")) {
                assertEquals("first / org.twia.vendor.VendorManagerTest.testGetVendorFirmKeyForVendorRep",
                        failed.getFullDisplayName());
                assertEquals(2, failed.getFailedSince());
            } else if (failed.getDisplayName().equals("first / testCreateAdjustingFirm")) {
                assertEquals("first / org.twia.vendor.VendorManagerTest.testCreateAdjustingFirm",
                        failed.getFullDisplayName());
                assertEquals(2, failed.getFailedSince());
            } else if (failed.getDisplayName().equals("first / testCreateVendorFirm")) {
                assertEquals("first / org.twia.vendor.VendorManagerTest.testCreateVendorFirm",
                        failed.getFullDisplayName());
                assertEquals(3, failed.getFailedSince());
            } else {
                fail("Failed test displayName " + failed.getDisplayName() + " is unexpected.");
            }
        }
    }
}
 
Example #23
Source File: DeflakeActionIntegrationTest.java    From flaky-test-handler-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public List<CaseResult> getFailedTests() {
  return DeflakeListenerTest.setupCaseResultList();
}