2

I am trying to achieve code coverage for source code from e2e tests. I used nyc npm module for coverage. It's able to provide coverage report on e2e tests files including page object files, but there is no coverage report for actual source file. Coverage report on e2e files just gives an idea how much of testing code is actually executed, but what what features are covered by e2e tests is not extracted.

Is there any way we can get feature source code files coverage from e2e tests?

Here is the code for getting coverage report.

  1. install nyc npm module.
  2. Add .nycrc.json at project root folder.
  3. Execute command nyc protractor protractor.conf.js

.nycrc.json file looks like this.

 {
  "include": [
    "src/**/*.ts",
    "e2e/**/*.ts"
  ],
  "exclude": [
    "/**/*.spec.ts",
    "**/*.d.ts"
  ],
  "extension": [
    ".ts"
  ],
  "reporter": [
    "text",
    "lcov"
  ]
}

It generates the report files but only for test code.

Lex
  • 6,758
  • 2
  • 27
  • 42
  • The short answer is no. Your e2e tests do not know anything about the underlying code and the path it takes through your app. Nor should they. If you want coverage stats you should use unit or integration tests. – tehbeardedone Jan 25 '19 at 17:59
  • Just to add to what @tehbeardedone said. e2e tests are meant to test the flow of applications rather than check each and every line of source code. For example, if your application is eCommerce website, then e2e testing will simulate the user and will make sure whether a product can be added to cart and purchased or not. Such thing cannot be tested with unit tests. – Saddam Pojee Jan 26 '19 at 08:22

0 Answers0