hudson.tasks.junit.TestResultAction Java Examples

The following examples show how to use hudson.tasks.junit.TestResultAction. 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: JUnitResultsStepTest.java    From junit-plugin with MIT License 6 votes vote down vote up
@Test
public void allowEmpty() throws Exception {
    WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "allowEmpty");
    j.setDefinition(new CpsFlowDefinition("stage('first') {\n" +
            "  node {\n" +
            (Functions.isWindows() ?
            "    bat 'echo hi'\n" :
            "    sh 'echo hi'\n") +
            "    def results = junit(testResults: '*.xml', allowEmptyResults: true)\n" +
            "    assert results.totalCount == 0\n" +
            "  }\n" +
            "}\n", true));

    WorkflowRun r = rule.buildAndAssertSuccess(j);
    assertNull(r.getAction(TestResultAction.class));
    rule.assertLogContains("None of the test reports contained any result", r);
}
 
Example #2
Source File: DeflakeListener.java    From flaky-test-handler-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void onCompleted(Run run, TaskListener listener) {
  // TODO consider the possibility that there is >1 such action
  TestResultAction testResultAction = run.getAction(TestResultAction.class);

  HistoryAggregatedFlakyTestResultAction historyAction = run.getParent()
      .getAction(HistoryAggregatedFlakyTestResultAction.class);

  // Aggregate test running results
  if (historyAction != null) {
    historyAction.aggregateOneBuild(run);
  }

  if (testResultAction != null && testResultAction.getFailCount() > 0) {
    // Only add deflake action if there are test failures
    run.addAction(
        new DeflakeAction(getFailingTestClassMethodMap(testResultAction.getFailedTests())));
  }
}
 
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: 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 #5
Source File: PipelineApiTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void getPipelineRunWithTestResult() throws Exception {
    FreeStyleProject p = j.createFreeStyleProject("pipeline4");
    p.getBuildersList().add(new Shell("echo '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
        "<testsuite xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd\" name=\"io.jenkins.blueocean.jsextensions.JenkinsJSExtensionsTest\" time=\"35.7\" tests=\"1\" errors=\"0\" skipped=\"0\" failures=\"0\">\n" +
        "  <properties>\n" +
        "  </properties>\n" +
        "  <testcase name=\"test\" classname=\"io.jenkins.blueocean.jsextensions.JenkinsJSExtensionsTest\" time=\"34.09\"/>\n" +
        "</testsuite>' > test-result.xml"));

    p.getPublishersList().add(new JUnitResultArchiver("*.xml"));
    FreeStyleBuild b = p.scheduleBuild2(0).get();
    TestResultAction resultAction = b.getAction(TestResultAction.class);
    assertEquals("io.jenkins.blueocean.jsextensions.JenkinsJSExtensionsTest",resultAction.getResult().getSuites().iterator().next().getName());
    j.assertBuildStatusSuccess(b);
    Map resp = get("/organizations/jenkins/pipelines/pipeline4/runs/"+b.getId());

    //discover TestResultAction super classes
    get("/classes/hudson.tasks.junit.TestResultAction/");

    // get junit rest report
    get("/organizations/jenkins/pipelines/pipeline4/runs/"+b.getId()+"/testReport/result/");
}
 
Example #6
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 #7
Source File: JUnitFlakyTestDataPublisher.java    From flaky-test-handler-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public TestResultAction.Data contributeTestData(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener, TestResult testResult)
    throws IOException, InterruptedException {
  VirtualChannel channel = launcher.getChannel();
  if(channel == null) {
        throw new InterruptedException("Could not get channel to run a program remotely.");
  }
  FlakyTestResult flakyTestResult = channel.call(new FlakyTestResultCollector(testResult));
  // TODO consider the possibility that there is >1 such action
  flakyTestResult.freeze(run.getAction(AbstractTestResultAction.class), run);
  return new JUnitFlakyTestData(flakyTestResult);
}
 
Example #8
Source File: JUnitResultsStepTest.java    From junit-plugin with MIT License 5 votes vote down vote up
private void assertExpectedResults(Run<?,?> run, int suiteCount, int testCount, String... nodeIds) throws Exception {
    TestResultAction action = run.getAction(TestResultAction.class);
    assertNotNull(action);

    TestResult result = action.getResult().getResultByNodes(Arrays.asList(nodeIds));
    assertNotNull(result);
    assertEquals(suiteCount, result.getSuites().size());
    assertEquals(testCount, result.getTotalCount());
}
 
Example #9
Source File: JUnitResultsStepTest.java    From junit-plugin with MIT License 5 votes vote down vote up
private static TestResult assertBlockResults(WorkflowRun run, int suiteCount, int testCount, int failCount, BlockStartNode blockNode) {
    assertNotNull(blockNode);

    TestResultAction action = run.getAction(TestResultAction.class);
    assertNotNull(action);

    TestResult aResult = action.getResult().getResultForPipelineBlock(blockNode.getId());
    assertNotNull(aResult);

    assertEquals(suiteCount, aResult.getSuites().size());
    assertEquals(testCount, aResult.getTotalCount());
    assertEquals(failCount, aResult.getFailCount());
    if (failCount > 0) {
        assertThat(findJUnitSteps(blockNode), CoreMatchers.hasItem(hasWarningAction()));
    } else {
        assertThat(findJUnitSteps(blockNode), CoreMatchers.not(CoreMatchers.hasItem(hasWarningAction())));
    }

    PipelineBlockWithTests aBlock = action.getResult().getPipelineBlockWithTests(blockNode.getId());

    assertNotNull(aBlock);
    List<String> aTestNodes = new ArrayList<>(aBlock.nodesWithTests());
    TestResult aFromNodes = action.getResult().getResultByNodes(aTestNodes);
    assertNotNull(aFromNodes);
    assertEquals(aResult.getSuites().size(), aFromNodes.getSuites().size());
    assertEquals(aResult.getFailCount(), aFromNodes.getFailCount());
    assertEquals(aResult.getSkipCount(), aFromNodes.getSkipCount());
    assertEquals(aResult.getPassCount(), aFromNodes.getPassCount());

    return aResult;
}
 
Example #10
Source File: JUnitResultsStepTest.java    From junit-plugin with MIT License 5 votes vote down vote up
@Issue("JENKINS-48196")
@Test
public void stageInParallel() throws Exception {
    WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "stageInParallel");
    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"));

    j.setDefinition(new CpsFlowDefinition("stage('outer') {\n" +
            "  node {\n" +
            "    parallel(a: { stage('a') { def first = junit(testResults: 'first-result.xml'); assert first.totalCount == 6 }  },\n" +
            "             b: { stage('b') { def second = junit(testResults: 'second-result.xml'); assert second.totalCount == 1 } },\n" +
            "             c: { stage('d') { def third = junit(testResults: 'third-result.xml'); assert third.totalCount == 3 } })\n" +
            "  }\n" +
            "}\n", true
    ));
    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());

    // assertBranchResults looks to make sure the display names for tests are "(stageName) / (branchName) / (testName)"
    // That should still effectively be the case here, even though there's a stage inside each branch, because the
    // branch and nested stage have the same name.
    assertBranchResults(r, 1, 6, 0, "a", "outer", null);
    assertBranchResults(r, 1, 1, 0, "b", "outer", null);
    // ...except for branch c. That contains a stage named 'd', so its test should have display names like
    // "outer / c / d / (testName)"
    assertBranchResults(r, 3, 3, 1, "c", "outer", "d");
}
 
Example #11
Source File: JUnitResultsStepTest.java    From junit-plugin with MIT License 5 votes vote down vote up
@Test
public void parallelInStage() throws Exception {
    WorkflowJob j = rule.jenkins.createProject(WorkflowJob.class, "parallelInStage");
    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"));

    j.setDefinition(new CpsFlowDefinition("stage('first') {\n" +
            "  node {\n" +
            "    parallel(a: { def first = junit(testResults: 'first-result.xml'); assert first.totalCount == 6 },\n" +
            "             b: { def second = junit(testResults: 'second-result.xml'); assert second.totalCount == 1 },\n" +
            "             c: { def third = junit(testResults: 'third-result.xml'); assert third.totalCount == 3 })\n" +
            "  }\n" +
            "}\n", true
    ));
    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());

    assertBranchResults(r, 1, 6, 0, "a", "first", null);
    assertBranchResults(r, 1, 1, 0, "b", "first", null);
    assertBranchResults(r, 3, 3, 1, "c", "first", null);
    assertStageResults(r, 5, 10, 1, "first");
}
 
Example #12
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 #13
Source File: TestResultsTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
@Test
public void testfromJUnitTestResultsEmpty() {
    TestResultAction testResultAction = mock(TestResultAction.class);
    when(testResultAction.getResult()).thenReturn(new TestResult());

    TestResults instance = TestResults.fromJUnitTestResults(testResultAction);
    
    assertNotNull(instance);
    assertEquals(0, instance.getPassedTestCaseCount());
    assertEquals(0, instance.getSkippedTestCaseCount());
    assertEquals(0, instance.getFailedTestCaseCount());
}
 
Example #14
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 #15
Source File: TestObject.java    From junit-plugin with MIT License 5 votes vote down vote up
/**
 * Get a list of all TestActions associated with this TestObject. 
 */
@Override
@Exported(visibility = 3)
public List<TestAction> getTestActions() {
    AbstractTestResultAction atra = getTestResultAction();
    if ((atra != null) && (atra instanceof TestResultAction)) {
        TestResultAction tra = (TestResultAction) atra;
        return tra.getActions(this);
    } else {
        return new ArrayList<TestAction>();
    }
}
 
Example #16
Source File: JUnitTestProvider.java    From phabricator-jenkins-plugin with MIT License 5 votes vote down vote up
private TestResult getJUnitResults() {
    Run<?, ?> build = getBuild();

    TestResultAction jUnitAction = build.getAction(TestResultAction.class);
    if (jUnitAction == null) {
        return null;
    }
    return jUnitAction.getResult();
}
 
Example #17
Source File: WithMavenStepOnMasterTest.java    From pipeline-maven-plugin with MIT License 5 votes vote down vote up
@Issue("JENKINS-27395")
@Test
public void maven_build_test_results_by_stage_and_branch() throws Exception {
    loadMavenJarProjectInGitRepo(this.gitRepoRule);

    String pipelineScript = "stage('first') {\n" +
            "    parallel(a: {\n" +
            "        node('master') {\n" +
            "            git($/" + gitRepoRule.toString() + "/$)\n" +
            "            withMaven() {\n" +
            "                sh 'mvn package verify'\n" +
            "            }\n" +
            "        }\n" +
            "    },\n" +
            "    b: {\n" +
            "        node('master') {\n" +
            "            git($/" + gitRepoRule.toString() + "/$)\n" +
            "            withMaven() {\n" +
            "                sh 'mvn package verify'\n" +
            "            }\n" +
            "        }\n" +
            "    })\n" +
            "}";

    WorkflowJob pipeline = jenkinsRule.createProject(WorkflowJob.class, "build-on-master");
    pipeline.setDefinition(new CpsFlowDefinition(pipelineScript, true));
    WorkflowRun build = jenkinsRule.buildAndAssertSuccess(pipeline);

    TestResultAction testResultAction = build.getAction(TestResultAction.class);
    assertThat(testResultAction.getTotalCount(), is(4));
    assertThat(testResultAction.getFailCount(), is(0));

    /*
    TODO enable test below when we can bump the junit-plugin to version 1.23+
    JUnitResultsStepTest.assertStageResults(build, 4, 6, "first");

    JUnitResultsStepTest.assertBranchResults(build, 2, 3, "a", "first");
    JUnitResultsStepTest.assertBranchResults(build, 2, 3, "b", "first");
    */
}
 
Example #18
Source File: WithMavenStepOnMasterTest.java    From pipeline-maven-plugin with MIT License 5 votes vote down vote up
/**
 *
 * <pre>
 * ERROR: [withMaven] jacocoPublisher - Silently ignore exception archiving JaCoCo results:
 * java.io.IOException: While reading class directory: /var/folders/lq/50t8n2nx7l316pwm8gc_2rt40000gn/T/j h8464991534006021463/jobs/jar-with-jacoco/builds/1/jacoco/classes
 * </pre>
 * @throws Exception
 */
@Ignore("IOException: While reading class directory: .../jacoco/classes")
@Test
public void maven_build_jar_with_jacoco_succeeds() throws Exception {
    loadMavenJarWithJacocoInGitRepo(this.gitRepoRule);

    String pipelineScript = "node('master') {\n" +
            "    git($/" + gitRepoRule.toString() + "/$)\n" +
            "    withMaven() {\n" +
            "        sh 'mvn package verify'\n" +
            "    }\n" +
            "}";

    WorkflowJob pipeline = jenkinsRule.createProject(WorkflowJob.class, "jar-with-jacoco");
    pipeline.setDefinition(new CpsFlowDefinition(pipelineScript, true));
    WorkflowRun build = jenkinsRule.assertBuildStatus(Result.SUCCESS, pipeline.scheduleBuild2(0));

   Collection<String> artifactsFileNames = TestUtils.artifactsToArtifactsFileNames(build.getArtifacts());
    assertThat(artifactsFileNames, hasItems("jar-with-jacoco-0.1-SNAPSHOT.pom", "jar-with-jacoco-0.1-SNAPSHOT.jar"));

    verifyFileIsFingerPrinted(pipeline, build, "jenkins/mvn/test/jar-with-jacoco/0.1-SNAPSHOT/jar-with-jacoco-0.1-SNAPSHOT.jar");
    verifyFileIsFingerPrinted(pipeline, build, "jenkins/mvn/test/jar-with-jacoco/0.1-SNAPSHOT/jar-with-jacoco-0.1-SNAPSHOT.pom");

    List<TestResultAction> testResultActions = build.getActions(TestResultAction.class);
    assertThat(testResultActions.size(), is(1));
    TestResultAction testResultAction = testResultActions.get(0);
    assertThat(testResultAction.getTotalCount(), is(1));
    assertThat(testResultAction.getFailCount(), is(0));

    List<JacocoBuildAction> jacocoBuildActions = build.getActions(JacocoBuildAction.class);
    assertThat(jacocoBuildActions.size(), is(1));
    JacocoBuildAction jacocoBuildAction = jacocoBuildActions.get(0);
    assertThat(jacocoBuildAction.getProjectActions().size(), is(1));
}
 
Example #19
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 #20
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 #21
Source File: WithMavenStepOnMasterTest.java    From pipeline-maven-plugin with MIT License 4 votes vote down vote up
@Test
public void maven_build_jar_project_on_master_succeeds() throws Exception {
    loadMavenJarProjectInGitRepo(this.gitRepoRule);

    String pipelineScript = "node('master') {\n" +
            "    git($/" + gitRepoRule.toString() + "/$)\n" +
            "    withMaven() {\n" +
            "        sh 'mvn package verify'\n" +
            "    }\n" +
            "}";

    WorkflowJob pipeline = jenkinsRule.createProject(WorkflowJob.class, "build-on-master");
    pipeline.setDefinition(new CpsFlowDefinition(pipelineScript, true));
    WorkflowRun build = jenkinsRule.assertBuildStatus(Result.SUCCESS, pipeline.scheduleBuild2(0));

    // verify Maven installation provided by the build agent is used
    // can be either "by the build agent with executable..." or "by the build agent with the environment variable MAVEN_HOME=..."
    jenkinsRule.assertLogContains("[withMaven] using Maven installation provided by the build agent with", build);

    // verify .pom is archived and fingerprinted
    // "[withMaven] Archive ... under jenkins/mvn/test/mono-module-maven-app/0.1-SNAPSHOT/mono-module-maven-app-0.1-SNAPSHOT.pom"
    jenkinsRule.assertLogContains("under jenkins/mvn/test/mono-module-maven-app/0.1-SNAPSHOT/mono-module-maven-app-0.1-SNAPSHOT.pom", build);

    // verify .jar is archived and fingerprinted
    jenkinsRule.assertLogContains("under jenkins/mvn/test/mono-module-maven-app/0.1-SNAPSHOT/mono-module-maven-app-0.1-SNAPSHOT.jar", build);

    Collection<String> artifactsFileNames = TestUtils.artifactsToArtifactsFileNames(build.getArtifacts());
    assertThat(artifactsFileNames, hasItems("mono-module-maven-app-0.1-SNAPSHOT.pom", "mono-module-maven-app-0.1-SNAPSHOT.jar"));

    verifyFileIsFingerPrinted(pipeline, build, "jenkins/mvn/test/mono-module-maven-app/0.1-SNAPSHOT/mono-module-maven-app-0.1-SNAPSHOT.jar");
    verifyFileIsFingerPrinted(pipeline, build, "jenkins/mvn/test/mono-module-maven-app/0.1-SNAPSHOT/mono-module-maven-app-0.1-SNAPSHOT.pom");

    //  verify Junit Archiver is called for maven-surefire-plugin
    jenkinsRule.assertLogContains("[withMaven] junitPublisher - Archive test results for Maven artifact jenkins.mvn.test:mono-module-maven-app:jar:0.1-SNAPSHOT " +
            "generated by maven-surefire-plugin:test", build);

    TestResultAction testResultAction = build.getAction(TestResultAction.class);
    assertThat(testResultAction.getTotalCount(), is(2));
    assertThat(testResultAction.getFailCount(), is(0));

    //  verify Junit Archiver is called for maven-failsafe-plugin
    jenkinsRule.assertLogContains("[withMaven] junitPublisher - Archive test results for Maven artifact jenkins.mvn.test:mono-module-maven-app:jar:0.1-SNAPSHOT " +
            "generated by maven-failsafe-plugin:integration-test", build);

    // verify Task Scanner is called for jenkins.mvn.test:mono-module-maven-app
    jenkinsRule.assertLogContains("[withMaven] openTasksPublisher - Scan Tasks for Maven artifact jenkins.mvn.test:mono-module-maven-app:jar:0.1-SNAPSHOT", build);
    TasksResultAction tasksResultAction = build.getAction(TasksResultAction.class);
    assertThat(tasksResultAction.getProjectActions().size(), is(1));
}
 
Example #22
Source File: JUnitResultsStepTest.java    From junit-plugin with MIT License 4 votes vote down vote up
@Override public TestResultAction.Data contributeTestData(Run<?,?> run, FilePath workspace, Launcher launcher, TaskListener listener, TestResult testResult) throws IOException, InterruptedException {
    return null;
}
 
Example #23
Source File: BlueTestResultContainerImplTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
public void setup() {
    testsToReturn = 12;
    Run<?, ?> run = mock(Run.class);
    when(run.getAction(TestResultAction.class)).thenReturn(null);
    container = new BlueTestResultContainerImpl(null, run);
}
 
Example #24
Source File: BuildStatusJobListener.java    From github-autostatus-plugin with MIT License 2 votes vote down vote up
/**
 * Gets test results from the build, if present.
 *
 * @param build the build
 * @return test results
 */
private TestResults getTestData(Run<?, ?> build) {
    TestResultAction testResultAction = build.getAction(TestResultAction.class);

    return TestResults.fromJUnitTestResults(testResultAction);
}