问题
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 intarget/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.
- Configure karma.conf.js to use 'karma-junit-reporter' and report to outputDir = 'target/karma-reports/'
- In your pom.xml, give the test execution step an execution/id like 'karmaTests'
- 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