git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 6/6] t/README: A new section about test coverage

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jul 24, 2010, 23:32 UTC
Message-ID
<20100724233232.GB6374@burratino>
In-Reply-To
<AANLkTim7v199lMKNEhOALx_38ChIIgvD4oERQJU5SNdv@mail.gmail.com>
Ævar Arnfjörð Bjarmason wrote:
>> Ævar Arnfjörð Bjarmason wrote:
>>> + - Check the test coverage for your tests. See the "Test coverage"
>>> +   below.
[...]
Show 14 quoted lines
> What I was going for here is that you should try to make sure that the
> code you're adding is covered by tests by running the coverage tests.
> 
> I.e. if I add a new function "blah" to git-whatever which is
> implemented by the "do_blah" function checking if every line of
> "do_blah" is covered is an excellent indicator of whether that code is
> being exhaustively tested, as opposed to just superficially tested.
> 
> In most cases a low test coverage counts is telling about the overall
> quality of the tests.
> 
> But, the wording can probably be improved. Do you have a suggestion
> for the above intent compressed into a sentence or two? I can't come
> up with anything right now.

What I meant is that when developing a new feature, I think paying too much attention to coverage numbers is a very dangerous thing.

It produces two hazards: too many tests and too few tests.
 - too many tests because when I write my "do_blah" function
   that is about a case no one cares about in practice, to write
   artificial tests to exercise would actually be to do harm.
 - too few tests because if I focus on testing all the code I
   just wrote, then I am very unlikely to include tests for the
   cases I did /not/ write code for.  Some important cases are
   just easy; we should still test them because that will help
   if the code is ever refactored later.  Some important cases
   may be just not implemented yet; test cases for them are
   very helpful indeed to readers and future implementers.

In other words, I would rather that when writing tests, authors would forget about the implementation for a moment and just think about what a user wants to do.

That said:

The rest of the time, checking test coverage does provide a very good indication about what features might not be well tested yet. So it is still a good way to decide where to /start/ writing tests.

Plus it’s great fun to look at. :)

Thanks, Jonathan

Previous: Ævar Arnfjörð Bjarmason
Message 19 of 19 in “Detailed test coverage reports for Git”
  1. 0/6 Detailed test coverage reports for GitÆvar Arnfjörð Bjarmason, Jul 24, 2010
  2. 1/6 gitignore: Ignore files generated by "make coverage"Ævar Arnfjörð Bjarmason, Jul 24, 2010
  3. 2/6 Makefile: Include subdirectories in "make cover" reportsÆvar Arnfjörð Bjarmason, Jul 24, 2010
  4. Thomas RastJul 24, 2010
  5. Ævar Arnfjörð BjarmasonJul 24, 2010
  6. Jonathan NiederJul 24, 2010
  7. Junio C HamanoJul 26, 2010
  8. 3/6 Makefile: Split out the untested functions targetÆvar Arnfjörð Bjarmason, Jul 24, 2010
  9. Thomas RastJul 24, 2010
  10. Ævar Arnfjörð BjarmasonJul 24, 2010
  11. 4/6 Makefile: Add coverage-report-cover-db targetÆvar Arnfjörð Bjarmason, Jul 24, 2010
  12. Thomas RastJul 24, 2010
  13. Ævar Arnfjörð BjarmasonJul 24, 2010
  14. 5/6 Makefile: Add coverage-report-cover-db-html targetÆvar Arnfjörð Bjarmason, Jul 24, 2010
  15. 6/6 t/README: A new section about test coverageÆvar Arnfjörð Bjarmason, Jul 24, 2010
  16. Jonathan NiederJul 24, 2010
  17. Jonathan NiederJul 24, 2010
  18. Ævar Arnfjörð BjarmasonJul 24, 2010
  19. Jonathan NiederJul 24, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.