SG.CodeCoverage
A code coverage library, used for Test Impact Analysis (or Continuous Testing) in our internal testing framework, as a replacement for vstest's inefficient data collectors.
How does it work?
SG Coverage works by weaving IL codes into project's assemblies using its Instrumenter type in the SG.CodeCoverage project. It injects a AddHit(int typeId, int methodId) method call that counts number of times the method visited, and creates a json map file that maps id of assemblies, types and their methods to their file paths, during this process.
The AddHit(int, int) method resides in the SG.CodeCoverage.Recorder project, which is an auto generated assembly for each instrumentation phase (inspired by AltCover, Coverlet and MiniCover) and holds the total number of types instrumented and an in-memory visit counter.
Steps to produce coverage results
- Instrument assemblies using
Instrumenterclass. This process outputs ajsonmap file. - When any method in the project is called, instrumented assemblies make sure that the
RecordingControllerServeris running and collecting data, and then sends the hit records to the server. - After running each test, you can call
RecorderControllerClient.SaveHitsAndReset(string outputPath). This will send a request to server to save the visited types and methods as a binary file likehits.test1.bin, then resets the counter. - After collecting test hits, you can find the visited files by merging the
jsonmap file and the binary hit file. This can be easily done usingDataCollector.GetVisitedFilesmethod which does this task.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
