我们正在使用karma作为jasmine单元测试的测试运行器,测试一个Angular应用程序。我们有超过6000个测试。Karma运行测试的速度很慢,从来没有超过2700个测试(11分钟)。
请问Karma可以运行的测试数量是否有限制,或者说随着测试数量的增加,测试运行器的性能下降这么多是正常的吗?
// Karma Config file
module.exports = function(config) {
config.set({
basePath: '../',
frameworks: ['jasmine'],
files: [
...list of files
],
proxies: {
'/images/': '/base/src/client/images/',
},
exclude: [
'src/client/app/window/window.js'
],
preprocessors: {
'**/*.partial.html': ['ng-html2js']
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['Chrome'],
singleRun: true,
concurrency: Infinity,
browserNoActivityTimeout: 100000,
plugins: [
'karma-jasmine',
'karma-chrome-launcher',
'karma-phantomjs-launcher',
'karma-firefox-launcher',
'karma-ie-launcher',
'karma-ng-html2js-preprocessor'
],
ngHtml2JsPreprocessor: {
moduleName: 'templates',
stripPrefix: 'src/client'
}
})
}
为了帮助减缓测试执行速度,我发现使用ng-bullet (https:/www.npmjs.compackageng-bullet)对加快我的测试速度很有帮助。 有了6k个测试,要把你的组件搬过来可能是件很困难的事,但你应该可以一次只搬一个规范文件,从较长的规范文件开始,看看它对执行时间有多大帮助。
另一个我用来帮助测试的方法是将测试分解成套件,这样你就可以并行地使用多个套件,或者在测试应用程序的特定部分时使用较小的块。 这篇文章谈到了这个概念以及使用ng-bullet。https:/www.forbes.comsitesforbesdigitalgroup20190514improve-your-angular-jasmine-unit-test-speeds-by-500#45ee76a14163