在Jenkins中发布Karma单元测试

6

Jenkins已经构建了我的Maven Java项目。我希望在Jenkins中显示karma单元测试的结果,但不幸的是我不能在Jenkins中引入任何配置更改。如何配置karma以实现这一目标?

3个回答

7
  • 为了使Jenkins能够解析karma测试结果,这些结果必须以JUnit XML格式发布。执行此操作的插件是karma-junit-reporter
  • karma配置文件中的junit测试结果(outputFile)必须存储在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/'
    }

0

虽然是旧文章,但在 Google 中排名靠前。

  1. 配置 karma.conf.js 使用 'karma-junit-reporter' 并报告到 outputDir = 'target/karma-reports/'
  2. 在 pom.xml 中,为测试执行步骤设置 execution/id,例如 'karmaTests'
  3. 在 pom.xml 中,设置属性 jenkins.karmaTest.reportsDirectory = target/karma-reports

完整的示例请参见 this blog post


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接