You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesi贸n a prueba de IA

Antes: $249

Currency
$209
Suscr铆bete

Termina en:

0 D铆as
14 Hrs
46 Min
7 Seg

Coverage Report

8/25
Resources

What is a test coverage report and why is it important?

Launching a coverage report on your development projects is crucial to make sure how many tests are running and what parts of your code are being covered. These reports guide you in determining which flows or endpoints are not yet covered in your current tests. Coverage does not measure the quality of the tests; it simply indicates which parts of the code have been "touched" during testing.

How to add tasks to generate a coverage report?

To generate a coverage report, you need to add specific configurations in your package.json file. Often these settings are separated so as not to overload a single command. Here's how you can do it:

  1. Adding a command in package.json:

    • Add a new task that includes a flag for coverage:
    { " scripts": { " test:e2e": "jest --coverage" }}
  2. Running the command:

    • Use the terminal to run the tests:
    npm run test:e2e
    • This command will generate a report that will be displayed in the terminal and will also create a coverage folder containing the report.

How to view the coverage report graphically?

Visual Studio Code makes it easy to find this report. Inside your project, when you run the tests, a folder named coverage is automatically created.

  1. Locate the folder:

    • By default, this folder is ignored in Git, ensuring that coverage reports are not uploaded to the repository.
  2. Open the report in a browser:

    • Within coverage, look for index.html which you can open with any web browser.
    • This file will show you graphically which parts of your code were executed during testing.

How to ensure complete coverage of your services?

Often, when running end-to-end (e2e) tests, you cover multiple lines of code simply by launching the application. However, to ensure more detailed coverage:

  • Be sure to create tests that interact with all important endpoints of your services.
  • Verify that at least the crucial services of your application are being adequately tested.

For example, make sure that routers, the authentication process and other important endpoints are covered in the tests. Develop specific tests for non-covered endpoints, such as login or data verification.

How to avoid coverage report collisions?

It is common that when integrating different types of tests, such as unit testing and end-to-end, coverage reports become intertwined. To prevent this:

  • Correctly configure the coverage directory in the configuration file, such as jest.config.js:

    module.exports = { coverageDirectory: 'coverage/e2e'};
  • Ignore coverage folders in Git: Add these new folders to your .gitignore file to prevent such reports from being logged in version control.

  • Run and verify: When re-running the npm run test:e2e command, make sure that your tests are generating reports only for the specified test type.

This methodical separation will help you maintain proper order when handling different types of tests, ensuring that each report is clear and useful for future code reviews and enhancements. Go ahead and continue exploring how to improve your testing capabilities!

Contributions 2

Questions 0

Sort by:

Want to see more contributions, questions and answers from the community?

A medida que crece nuestro proyecto, las buenas pruebas son las que garantizan que podamos hacerle mantenimiento a nuestro c贸digo sin romper nada o al menos d谩ndonos la oportunidad de darnos cuenta y repararlo antes de afectar a los usuarios

Para recordar: El reporte de cobertura **no** es para saber si estamos haciendo buenas pruebas o malas pruebas. Solo nos indica <u>qu茅 partes de nuestra aplicaci贸n no est谩n siendo probadas</u>.