本文介绍了在所有测试运行之前,业力断开连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们将karma用作茉莉花单元测试的测试运行程序,测试Angular应用程序.我们有6000多个测试.业力运行测试是如此缓慢,并且从未超过约2700个测试(11分钟).

We are using karma as the test runner for jasmine unit tests, testing an Angular application. We have over 6000 tests. Karma is so slow to run tests, and never gets past about 2700 tests (11 mins).

Karma可以运行的测试数量是否受到限制,或者随着测试数量的增加,测试运行器的性能下降是否正常?

Is there a limit to the number of tests Karma can run, or is it normal for the performance of the test runner to degrade so much as the number of tests increase?

// 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.com/package/ng-bullet )对于加快测试速度非常有帮助.通过6k测试,转移组件可能是一项艰巨的任务,但是您应该能够一次从一个冗长的规范开始一次制作一个规范文件,以查看它对执行时间有多大帮助.

To help slow test execution I have found using ng-bullet (https://www.npmjs.com/package/ng-bullet) has been quite helpful in speeding up my tests. With 6k tests, it would probably be quite an undertaking to get your components moved over but you should be able to do it one spec file at a time starting with the lengthier specs to see how much it helps execution time.

我用来帮助测试的另一件事是将测试分为套件,这样,如果测试应用程序的特定部分,则可以并行或以较小的块的形式使用多个套件.本文讨论了该概念以及如何使用ng-bullet: https://www.forbes.com/sites/forbesdigitalgroup/2019/05/14/improve-your-angular-jasmine-unit-test-speeds -by-500/#45ee76a14163

Another thing I've used to help with tests is by breaking the tests up into suites so that you can multiple suites in parallel or in smaller chunks if testing a specific part of the application. This article talks about that concept as well as using ng-bullet: https://www.forbes.com/sites/forbesdigitalgroup/2019/05/14/improve-your-angular-jasmine-unit-test-speeds-by-500/#45ee76a14163

这篇关于在所有测试运行之前,业力断开连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 19:39