Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a code coverage for HTML using Karma when doing angular e2e test?

We can use coverage to see how much javascript code is covered with our unit testing. With e2e testing we are literally testing view components in HTML code against controller. So the question is, is there same code coverage available for how much of HTML DOM elements are covered or touched in our e2e testing? I agree, there is a big difference in the execution path testing and UI testing. but curious. Thanks

like image 887
Nair Avatar asked May 13 '13 04:05

Nair


People also ask

How can you see the code coverage of the tests in your project angular?

To generate a coverage report run the following command in the root of your project. When the tests are complete, the command creates a new /coverage folder in the project. Open the index. html file to see a report with your source code and code coverage values.

How do I check my code coverage?

To calculate the code coverage percentage, simply use the following formula: Code Coverage Percentage = (Number of lines of code executed by a testing algorithm/Total number of lines of code in a system component) * 100.

How do I get code coverage for Jasmine?

the actual code coverage of those tests would reveal if the application is thoroughly stressed or not. for tests written using the famous jasmine test library, an easy way to have the coverage report is via istanbul and karma .

What is the use of angular karma in testing?

Karma is an open-source test runner for JavaScript created by the angular team. Karma can be easily integrated into your project and makes it easy to execute tests using CLI. Karma is useful for executing the tests on browsers, other devices like phones, tablets. Karma can be configured with different test frameworks including Jasmine, Mocha, Quit.

How do I create code coverage reports in angular?

When the tests are complete, the command creates a new /coverage folder in the project. Open the index.html file to see a report with your source code and code coverage values. If you want to create code-coverage reports every time you test, set the following option in the CLI configuration file, angular.json:

What is the default browser for Karma testing?

By default it is chrome but you can install and use other browser launchers. The angular-cli configuration of karma uses the file “test.ts” as the entry point of the tests for the application. Let’s take a look to that file; We have a lot of things going on here.

How do I enable 80% code coverage in karma?

To enable this, open the Karma test platform configuration file, karma.conf.js, and add the check property in the coverageReporter: key. The check property causes the tool to enforce a minimum of 80% code coverage when the unit tests are run in the project.


1 Answers

As I know e2e testing use your files served by your web server, for unit test they are served directly by karma, e2e testing is mostly used to be sure your page work like you expect, end-to-end test use your server side and client side. That's why you typically never expected to have 100% e2e coverage because they are more fragile.

So people focus on unit test (testing all edge-cases), and they add e2e test to be sure the behavior of the page works correctly.

You can use istanbul and build the coverage report with karma.

http://gotwarlost.github.io/istanbul/

Or this article : http://lkrnac.net/blog/2014/04/measuring-code-coverage-by-protractor/ sum up how to use protractor e2e to generate coverage report of your e2e tests. Using using this tool : https://github.com/r3b/grunt-protractor-coverage

Hope it's help.

like image 126
rbinsztock Avatar answered Nov 15 '22 07:11

rbinsztock