gpt4 book ai didi

angularjs - AngularJS 中 Protractor 测试的代码覆盖率

转载 作者:行者123 更新时间:2023-12-02 22:16:06 28 4
gpt4 key购买 nike

我正在我的 angularJS 应用程序中使用 Protractor 运行一些 e2e 测试(如 angularJS 文档中建议的那样)。我用谷歌搜索了一下,找不到任何关于如何测量 Protractor 测试覆盖范围的信息。

我想我在这里遗漏了一些东西...有没有办法获得 Protractor e2e 测试的代码覆盖率报告?或者它只是单元测试的一个功能?

最佳答案

这可以使用 Istanbul 来实现。以下是该过程,其中包含我从项目中提取的一些示例配置(未测试):

  1. 使用命令 istanbul instrument 检测您的代码。确保 Istanbul 尔的覆盖范围变量为 __coverage__ .

    // gulpfile.js

    gulp.task('concat', function () {
    gulp.src(PATH.src)
    // Instrument for protractor-istanbul-plugin:
    .pipe(istanbul({coverageVariable: '__coverage__'}))
    .pipe(concat('scripts.js'))
    .pipe(gulp.dest(PATH.dest))
    });
  2. 使用插件 protractor-istanbul-plugin 配置 Protractor .

    // spec-e2e.conf.js
    var istanbulPlugin = require('protractor-istanbul-plugin');

    exports.config = {
    // [...]
    plugins: [{ inline: istanbulPlugin }]
    };
  3. 运行测试。

  4. 使用 istanbul report 提取报告.

这种方法对我很有效,并且也很容易与单元测试的覆盖率报告结合起来。为了实现自动化,我已将步骤 1 放入我的 gulpfile.js 中以及 test 中的步骤 3 和 4和posttest package.json 中的脚本,或多或少像这样:

// In package.json:
"scripts": {
"test": "gulp concat && protractor tests/spec-e2e.conf.js",
"posttest": "istanbul report --include coverage/**/.json --dir reports/coverage cobertura"
},

关于angularjs - AngularJS 中 Protractor 测试的代码覆盖率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22350680/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com