角度2的代码覆盖率 [英] Code coverage for angular 2

查看:135
本文介绍了角度2的代码覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何找到角度2代码的代码覆盖率?我可以使用vs代码编辑器或webstorm的任何插件吗?我正在使用Jasmine和Karma进行代码的单元测试.

How do you find the code coverage for angular 2 code? Is there any plugin for vs code editor or webstorm that I can use? I am using Jasmine and Karma for unit testing of my code.

推荐答案

如果您想查看总体测试覆盖率统计信息,而不是在Angular CLI中,可以直接键入,然后查看命令提示符窗口的底部

If you want to see overall test coverage statistics than of course in Angular CLI you can just type, and see the bottom of your command prompt window

ng test --code-coverage

结果:

如果要查看组件的各个测试范围,请执行以下步骤.

if you want to see component's individual coverage of tests follow these steps.

  1. npm install --save-dev karma-teamcity-reporter

require('karma-teamcity-reporter')添加到karma.conf.js中的插件列表中

Add require('karma-teamcity-reporter') to list of plugins in karma.conf.js

ng test --code-coverage --reporters=teamcity,coverage-istanbul

请注意,由于我们添加了新的报告人teamcity,因此报告人的列表以逗号分隔.

note that list of reporters is comma-separated, as we have added a new reporter, teamcity.

运行此命令后,您可以在目录中看到文件夹coverage,并打开index.html以查看测试覆盖率的图形视图.

after running this command you can see the folder coverage in your dir and open index.html for a graphical view of test coverage.

您也可以像这样在karma.conf.js中设置要达到的覆盖范围阈值.

You can also set the coverage threshold that you want to achieve, in karma.conf.js, like this.

coverageIstanbulReporter: {
      reports: ['html', 'lcovonly'],
      fixWebpackSourcePaths: true,
      thresholds: {
        statements: 90,
        lines: 90,
        branches: 90,
        functions: 90
      }
    },

这篇关于角度2的代码覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆