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
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.
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.
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 .
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.
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:
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With