Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publish Karma unit tests in Jenkins

Jenkins already builds my Maven Java project. I want the results of karma unit tests to show up in Jenkins, but unfortunately I cannot introduce any configuration changes in Jenkins. How karma should be configured to acomplish that?

like image 872
Adam Siemion Avatar asked Dec 23 '14 08:12

Adam Siemion


People also ask

Can Jenkins run unit tests?

Jenkins provides an out of box functionality for Junit, and provides a host of plugins for unit testing for other technologies, an example being MSTest for . Net Unit tests. If you go to the link https://wiki.jenkins-ci.org/display/JENKINS/xUnit+Plugin it will give the list of Unit Testing plugins available.


2 Answers

  • in order for Jenkins to be able to parse karma test results they must be published in the Junit XML format, the plugin that does that is karma-junit-reporter
  • junit test results (outputFile in the karma configuration file) must be stored in target/surefire-reports/TESTS-TestSuite.xml
like image 143
Adam Siemion Avatar answered Oct 05 '22 22:10

Adam Siemion


    reporters        : ['progress', 'junit', 'coverage'],
    port             : 9876,
    colors           : true,
    logLevel         : config.LOG_INFO,
    // don't watch for file change
    autoWatch        : false,
    // only runs on headless browser
    browsers         : ['PhantomJS'],
    // just run one time
    singleRun        : true,
    // remove `karma-chrome-launcher` because we will be running on PhantomJS
    // browser on Jenkins
    plugins          : [
        'karma-jasmine',
        'karma-phantomjs-launcher',
        'karma-junit-reporter',
        'karma-coverage',
        'karma-jenkins-reporter'
    ],
    // changes type to `cobertura`
    coverageReporter : {
        type : 'cobertura',
        dir  : 'target/coverage-reports/'
    },
    // saves report at `target/surefire-reports/TEST-*.xml` because Jenkins
    // looks for this location and file prefix by default.
    junitReporter    : {
        outputDir : 'target/surefire-reports/'
    }
like image 27
nsk Avatar answered Oct 05 '22 22:10

nsk