我想获得一份关于所有成功的茉莉花规格报告的报告,就像你单独使用茉莉花时所得到的那样。
无论如何要实现这个目标吗?
答案 0 :(得分:21)
试试这个我写的快速插件:
答案 1 :(得分:8)
是的,但这不是微不足道的,如果你想要--auto-watch
则更是如此。所以,基本上没有:-(归咎于lib/reporters/Progress.js,它吞下了成功的测试结果,并为每个浏览器吐出一条汇总线。
如果你有决心,你有(至少)两种非平凡的方式(在 v0.9.2 )获得“足够好”的结果(其中一个,如果你这样做,你应该提升并提交拉动请求: - ))
与大多数测试框架一样,您可以让Karma在jUnit XML format中输出结果,然后您可以对其进行后期处理...
默认情况下,karma start --reporters=junit
会将jUnit报告写入${basePath}/test-results.xml
,但您可以使用junitReporter.outputFile
配置项覆盖此报告。
请记住,您可以在命令行上将jUnit输出与其他记者(咆哮等)结合使用:例如,karma start --reporters=junit,growl
我总是最终滚动我自己的傻瓜grep / sed / perl / etc。像这样的情况下的管道,但xmlstarlet非常适合这项工作。如,
$ cat test-runner.xml \
| xml sel -t -m "//testcase" -v @classname -o " " -v @name -nl
收益率(对于我的一个项目):
Chrome 27.0 (Linux).Globalization API: _g11n exists
Chrome 27.0 (Linux).Globalization API: _g11n has been initialized
Chrome 27.0 (Linux).Globalization API: _g11n _locales exists
Chrome 27.0 (Linux).Globalization API: _g11n _locales has been initialized
Chrome 27.0 (Linux).Globalization API: _g11n _locales has a current locale (matching the default)
Chrome 27.0 (Linux).Globalization API: _g11n _locales registry allows lookup by full code
Chrome 27.0 (Linux).Globalization API: _g11n _locales registry allows lookup by locale object
Chrome 27.0 (Linux).Globalization API: _g11n _locales registry fails
Chrome 27.0 (Linux).Globalization controllers hkmLocaleCtrl should have the locales database
如果您准备好了,请为现有的报告者(例如lib/reporters/Progress.js
,lib/reporters/Base.js
)创建子类,覆盖.specSuccess
和.onBrowserComplete
方法以报告更多详细信息每次测试。获得业力使用记者留给读者的练习: - )
BTW:如果你选择选项2,请务必打开拉动请求以使其进入业力: - )
答案 2 :(得分:2)
为了显示单个测试用例,我使用以下内容(从头开始进行基本单元测试项目):
npm install karma karma-jasmine karma-phantomjs-launcher karma-spec-reporter
touch main.js main.spec.js
karma init
然后选择以下问题:
Which testing framework do you want to use ?
> jasmine
Do you want to capture any browsers automatically ?
> PhantomJS
>
What is the location of your source and test files ?
> *.js
Do you want Karma to watch all the files and run the tests on change ?
> yes
编辑项目文件夹中的 karma.conf.js 和
替换:
记者:['进展']
with:
记者:[' spec']
运行
karma start
您已准备好在main.spec.js
中编写单元测试describe('suite', function () {
it('expectation', function () {
expect(true).toBeTruthy();
});
});
保存...在终端中你应该看到类似的内容:
INFO [watcher]: Changed file"/main.spec.js".
true
✓ should be true
PhantomJS 1.9.8 (Mac OS X): Executed 1 of 1 SUCCESS (0.001 secs / 0 secs)
答案 3 :(得分:-1)
有业力覆盖,可以创建.html代码覆盖率报告。它可以直接将它集成到你的业力配置中。
https://github.com/karma-runner/karma-coverage
npm install karma-coverage --save-dev
添加到karma.conf.js:
// karma.conf.js
module.exports = function(config) {
config.set({
files: [
'src/**/*.js',
'test/**/*.js'
],
// coverage reporter generates the coverage
reporters: ['progress', 'coverage'],
preprocessors: {
// source files, that you wanna generate coverage for
// do not include tests or libraries
// (these files will be instrumented by Istanbul)
'src/*.js': ['coverage']
},
// optionally, configure the reporter
coverageReporter: {
type : 'html',
dir : 'coverage/'
}
});
};