Publish Karma unit tests in Jenkins

六月ゝ 毕业季﹏ 提交于 2020-05-26 05:30:41

问题


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?


回答1:


  • 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



回答2:


    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/'
    }



回答3:


Old post, but top result in Google.

  1. Configure karma.conf.js to use 'karma-junit-reporter' and report to outputDir = 'target/karma-reports/'
  2. In your pom.xml, give the test execution step an execution/id like 'karmaTests'
  3. In your pom.xml, set a property jenkins.karmaTest.reportsDirectory = target/karma-reports

Full examples are on this blog post.



来源:https://stackoverflow.com/questions/27616657/publish-karma-unit-tests-in-jenkins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!