eloidieme / DD2480_Coverage

Scrapy, a fast high-level web crawling & scraping framework for Python.
https://scrapy.org
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Improve the test coverage of the _get_serialized_fields function #6

Open eloidieme opened 8 months ago

eloidieme commented 8 months ago

Keep a record (copy) of your coverage before you start working on new tests. Furthermore, make sure you add the new tests on a different branch than the one you used for coverage instrumentation. Having identified “weak spots” in coverage, try to improve coverage with additional test cases.

  1. Identify the requirements that are tested or untested by the given test suite.
  2. Document the requirements (as comments), and use them later as assertions.
  3. Create new test cases as needed to improve branch coverage in the given functions. Can you call the function directly? Can you expand on existing tests? Do you have to add additional interfaces to the system (as public methods) to make it possible to set up test data structures?
  4. If you have 100 % branch coverage, you can choose other functions or think about path coverage. You may cover all branches in a function, but what does this mean for the combination of branches? Consider the existing tests by hand and check how they cover the branches (in which combinations).
eloidieme commented 8 months ago
eloidieme commented 8 months ago

Identified requirements

eloidieme commented 8 months ago
eloidieme commented 8 months ago

Now coverage for the function is 92%. Only one non-covered branch left.

Capture d’écran 2024-02-21 à 00 03 38
eloidieme commented 8 months ago

Finally, coverage is 100% with this second test added.

Capture d’écran 2024-02-21 à 00 10 08
eloidieme commented 8 months ago

Notes: the function can be called directly in the test suite through the class it belongs to. It was easier to write new tests than to expand on existing tests. I didn't need to add additional interfaces.