0
votes

I am running karma.js for unit testing and integrating with jenkins pipeline. My goal is to read the type of error thrown from Karma, if it is error related to percentage i want to terminate the job, otherwise continue even if there are other errors like unit test failures etc. (this is a requirement and there are reasons for it.)

I didn't find a way to do this. Any thoughts are appreciated!

karma start ibx-test/olb/karma.conf.js --browsers PhantomJS --log-level warn --single-run


coverageReporter: {
        type: 'lcov',
        dir: 'unit-tests/coverage/',
            check: {
                global: {
                lines: 100 //This is just for testing
                }
            }
    }

16:17:43 [Unit Test] 09 03 2017 21:17:43.024:ERROR [coverage]: PhantomJS 2.1.1 (Linux 0.0.0): Coverage for lines (90.33%) does not meet global threshold (100%)

EDIT: I found "Process xUnit test result report" in pipeline syntax under "Build step", can i use this somehow? Is there correlation between karma reports and xUnit?

1

1 Answers

0
votes

i found a way to do this. The "Process xUnit test result report" helps doing exactly this. I checkedout the Pipeline syntax and it gave me the below script and it worked.

step([$class: 'XUnitBuilder', testTimeMargin: '3000', thresholdMode: 1, 
    thresholds: [
     [$class: 'FailedThreshold', failureNewThreshold: '', 
              failureThreshold: '2', unstableNewThreshold: '', 
              unstableThreshold: '1'], 
     [$class: 'SkippedThreshold', failureNewThreshold: '', 
            failureThreshold: '', unstableNewThreshold: '', 
            unstableThreshold: '']], 
    tools: [[$class: 'JUnitType', deleteOutputFiles: false, 
      failIfNotNew: false, pattern: 'ibx-test/reports/unit-tests/PhantomJS_2.1.1_(Linux_0.0.0)/ibx-test/reports/unit-tests/*.xml',
      skipNoTestFiles: false, stopProcessingIfError: false]]])
  • thresholdMode: means number of (failed or skipped) tests will be used for threshold. 1 for number and 2 for percent. I used 1, so i could just make one test fail and i get the desired result.
  • FailedThreshold: Is the class to be used for threshold for failures.
  • SkippedThreshold: can be used for skipped tests. I am not using it yet.

I am not paying attention on other parameters as of now for this testing.

As you can see my value is 2 (failureThreshold: '2'). As soon as i have 2 tests failing, the build fails and terminates.