Which line was run by which test?

Before I invest a bunch of time in writing one, does there exist a library which reports code coverage on a per-test basis? That is: if I look at a code coverage report, I want to be able to tell which test (or tests) were responsible for a particular line being run.


I don’t think it exists but I would love to have one! I would be a pretty heavy user of it.


If you are not afraid of commercial tools, then eqc_cover may be an option for you.

(Part of the QuickCheck bundle)


Yep, it does not exist in the wild, and in fact not that easy to do. I briefly talked about “test selection” feature that we use internally (although on a per-SUITE base rather than per-testcase). I briefly mentioned that during my last CodeBEAM talk, one goal I have for next year is to make this available for wider community.


A naive approach (i.e. the one I was going to try first) would simply take a before and after snapshot for each test and then compare them. Did you try this and find something wrong with it? I’d rather not try something that’s already been proven to be bad.

1 Like

It does not scale well. For small number (<1000) it might be fine, but any larger project takes ages to run sequentially (or has to be sharded to some really large number of separate machines/containers).

1 Like