Forum Discussion

rajat_wrk's avatar
rajat_wrk
Occasional Contributor
4 years ago

Groovy Rerun Failed Test Case Execution Report

I am using groovy script to rerun failed test cases but in Junit-Style Report , the test cases are still coming as failed even though they got passed after several retries. 

 

Could you please let me know how to ensure that only the final execution test status is available in the report.

 

Please find the link for groovy script used for rerunning failed test cases : https://community.smartbear.com/t5/API-Functional-Security-Testing/Groovy-script-to-re-run-failed-tests/td-p/168404

  • nmrao's avatar
    nmrao
    4 years ago

    rajat_wrk wrote:

     

    The point here is not the execution but the reporting, after multiple retries if the Test Cases is passed it is  marked  as Pass at Test Suit level on the tool interface but in the Test Suit Printable Report is still shows fail.


    It is being addressed the issue incorrectly. First look for the reason why it is happening. If the services works with definitive behavior, then there is no issue of reporting.

     


    rajat_wrk wrote:

    I have added assertion as a Test step in the test case. Since, the assertion can pass only if the value in response matches the assertion value, the test case may fail on multiple retries but it will keep on re running for a fixed number of times.

    Please check with your team why such indefinitve behavior?

    How will the end user / customer use it if one can't predict the expected response based on the input?

     

    For each fixed input, the response should always be predictable. And respective assertions must always pass. Otherwise, I am afraid the application behavior can be acceptable.

  • nmrao's avatar
    nmrao
    Champion Level 3
    Summary is not aligned with the question.
    How are you generating the report? How some one can reproduce the issue?

  • James462's avatar
    James462
    Occasional Visitor

    @FaceTime PC wrote:

    I am using groovy script to rerun failed test cases but in Junit-Style Report , the test cases are still coming as failed even though they got passed after several retries. 

     

    Could you please let me know how to ensure that only the final execution test status is available in the report.

     

    Please find the link for groovy script used for rerunning failed test cases : https://community.smartbear.com/t5/API-Functional-Security-Testing/Groovy-script-to-re-run-failed-tests/td-p/168404


    This is not very handy. If I would have an automated Jenkins build that build would not be green in the described situation.

    I looked for a way to 'forget' the previous failed run of a particular test case but I didn't manage to find a solution.

    • rajat_wrk's avatar
      rajat_wrk
      Occasional Contributor

      nmrao  sorry for the confusion.

       

      Here's the  teardown script at project level I am using:

       

      def testSuiteResults = context.getTestRunner().getResults()
      def testCaseResults
      def runCount =0
      def testPassed = true

      // Iterate through each test case in the project
      testSuiteResults.each {
      it.getResults().each {
      // PASSED test case
      if ( it.getStatus().toString().equals("PASS") ) {
      log.info "The test case '" + it.getTestCase().getName() + "' has passed!"
      // FAILED test case
      } else {
      testPassed = false
      log.info "The test case '" + it.getTestCase().getName() + "' has failed!"
      runCount =0
      // Rerunning the failed test case...
      while ((runCount < 40) && (testPassed == false)) {
      log.info "Rerunning the test for the " +runCount +"time"
      if (it.getTestCase().run(new com.eviware.soapui.support.types.StringToObjectMap(), false).getStatus().toString().equals("PASS")) {
      testPassed = true
      log.info "The test case "+ it.getTestCase().getName() + " case has eventually passed!"
      } else {
      log.info "The test case "+ it.getTestCase().getName() + " did not pass"
      }
      runCount++
      }
      }
      }
      }

       

      Using this script  I am able the  re-run failed test cases for maximum 40 times and test case may pass eventually. The issue is Junit-style report generated from tool still shows them as failed even if they pass after several retries.

      Is there a way to keep the final result in the report?

       

      • nmrao's avatar
        nmrao
        Champion Level 3
        Sorry, don't have any ideas in this case, unless you adopt some kind of program to achieve what you need.
        However, I would do this:
        1. No one will run the tests for 40 times to make them pass or run untill they pass. Look for the root cause such as
        a. is it related to enviroment?
        b. is it related to application issue?
        c. any latencies between the test machines and the application?
        d. any test dependencies? or data shared between them?

        2. Irrespective of the above, try to run all the tests once and generate report in single short.