我很难开始为我的应用程序编写单元测试。我的覆盖率总是报告 100%。我做了简单的测试,结果应该是 50%,但业力覆盖率不这么认为。业力进展如何报告正确的结果,但我需要使覆盖工作。
这是我的 karma.conf.coffee:
module.exports = (config) ->
config.set
basePath: ""
frameworks: ["jasmine"]
files: [
#"server/*_spec.js",
#"server/*.js",
#"client/app/final/.js"
#"client/*_spec.js"
"test.js"
"test_spec.js"
]
exclude: []
preprocessors: {}
reporters: ["progress", "coverage"]
preprocessors:
"test.js": ["coverage"]
coverageReporter:
type : "html",
dir : "coverage/"
port: 9876
colors: true
logLevel: config.LOG_INFO
autoWatch: false
browsers: [
"Chrome"
#"Firefox" add to package.json::devDependencies:["karma-firefox-launcher"]
#"PhantomJS" add to package.json::dependencies:["phantomjs"] and package.json::devDependencies["karma-phantomjs-launcher"]
]
singleRun: true
concurrency: Infinity
这是 test.js:
function test(a) {
return a
}
function ivo() {
return "ivo"
}
最后是 test_spec.js
describe("test", function() {
it("it tests", function() {
expect(test(3)).toEqual(3);
});
});
describe("ivo", function() {
it("it ivos", function() {
expect(ivo()).toEqual("ovi");
});
});
业力进度结果:
karma start
31 12 2015 17:12:48.598:INFO [karma]: Karma v0.13.16 server started at http://localhost:9876/
31 12 2015 17:12:48.610:INFO [launcher]: Starting browser Chrome
31 12 2015 17:12:50.007:INFO [Chrome 47.0.2526 (Linux 0.0.0)]: Connected on socket q97o45wS4ctU_z4DAAAA with id 35753464
Chrome 47.0.2526 (Linux 0.0.0) ivo it ivos FAILED
Expected 'ivo' to equal 'ivo1'.
at Object.<anonymous> (/home/ivo/ivo/diplomna3/test_spec.js:9:19)
Chrome 47.0.2526 (Linux 0.0.0): Executed 2 of 2 (1 FAILED) (0.004 secs / 0.01 secs)