Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-63260

JUnit Plugin still aggregates the results of already cleaned up test reports

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Component/s: junit-plugin
    • Labels:
      None
    • Environment:
      Windows 10
    • Similar Issues:

      Description

      JUnit Plugin still aggregates the results of already cleaned up test reports. From the example below in a declarative pipeline, there are 2 stages each of them starts by cleaning up the reports directory, triggering the build to generate the reports, harvest the results through AbstractTestResultAction.class. The issue is that after running stage 2, the testResultAction.totalCount becomes 5 wherein it should only be 3 since the 2 test cases from the stage 1 were already deleted. 

      If this is something that can't be fixed as it is an expected behavior of the jenkins junit core, is there a way to empty the results that were harvested from the previous stages?

       

       

      stage('1'){  
                   //Insert code to delete test-output directory here
                   //Insert build trigger here with 2 Test Cases
      
                          junit '***/test-output/TEST-com.TestA.xml'
      
                          script {
                              AbstractTestResultAction testResultAction =  currentBuild.rawBuild.getAction(AbstractTestResultAction.class)
                              if (testResultAction != null) {
                                  def totalNumberOfTests = testResultAction.totalCount
                                  def failedNumberOfTests = testResultAction.failCount
                                  def failedDiff = testResultAction.failureDiffString
                                  def skippedNumberOfTests = testResultAction.skipCount
                                  def passedNumberOfTests = totalNumberOfTests - failedNumberOfTests - skippedNumberOfTests
                                  emailTestReport = "Tests Report:\n Passed: ${passedNumberOfTests}; Failed: ${failedNumberOfTests} ${failedDiff}; Skipped: ${skippedNumberOfTests}  out of ${totalNumberOfTests} "
                              }
                          }
                      }
      
                  }
              }
      
      stage('2'){
      
                 //Insert Code to delete test-output directory here
                //Insert build trigger here with 3 Test Cases
                          junit '***/test-output/TEST-com.TestB.xml''
                          script {
                              AbstractTestResultAction testResultAction =  currentBuild.rawBuild.getAction(AbstractTestResultAction.class)
                              if (testResultAction != null) {
                                  def totalNumberOfTests = testResultAction.totalCount
                                  def failedNumberOfTests = testResultAction.failCount
                                  def failedDiff = testResultAction.failureDiffString
                                  def skippedNumberOfTests = testResultAction.skipCount
                                  def passedNumberOfTests = totalNumberOfTests - failedNumberOfTests - skippedNumberOfTests
                                  emailTestReport = "Tests Report:\n Passed: ${passedNumberOfTests}; Failed: ${failedNumberOfTests} ${failedDiff}; Skipped: ${skippedNumberOfTests}  out of ${totalNumberOfTests} "
                              }
                          }
                      }
      
                  }
              }
      

       

        Attachments

          Activity

          Hide
          timja Tim Jacomb added a comment -

          You could remove the action?

          From what I can tell you're only supposed to run the `junit` step once per build

          Show
          timja Tim Jacomb added a comment - You could remove the action? From what I can tell you're only supposed to run the `junit` step once per build
          Hide
          kdpanaglima kevin pan added a comment -

          Hi Tim Jacomb

          On second stage? Tried to remove the action declaration on that but the Count variables are unable to call the action from the first stage.  

          I'm thinking if there's other way to harvest the results without using the AbstractTestResultAction. 

          Show
          kdpanaglima kevin pan added a comment - Hi Tim Jacomb ,  On second stage? Tried to remove the action declaration on that but the Count variables are unable to call the action from the first stage.   I'm thinking if there's other way to harvest the results without using the AbstractTestResultAction. 
          Hide
          timja Tim Jacomb added a comment -

          you can move your junit into the script block and then get the results from the step returning.

          example:
          https://github.com/jglick/junit-plugin/blob/external-storage/src/test/java/hudson/tasks/junit/storage/TestResultStorageTest.java#L102

          Show
          timja Tim Jacomb added a comment - you can move your junit into the script block and then get the results from the step returning. example: https://github.com/jglick/junit-plugin/blob/external-storage/src/test/java/hudson/tasks/junit/storage/TestResultStorageTest.java#L102
          Hide
          kdpanaglima kevin pan added a comment -

          Hi Tim Jacomb,

          I am getting a 404 Error when opening the link you provided. 

          Show
          kdpanaglima kevin pan added a comment - Hi Tim Jacomb , I am getting a 404 Error when opening the link you provided. 

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            kdpanaglima kevin pan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: