Is it possible to run Scala SBT Scoverage without running 'sbt clean'
Asked Answered
C

1

9

It would be great if one can take advantage of sbt incremental compilation and avoid having to recompile the whole project every time you run your tests, which is exactly what happens when you do clean. The following sequence though:

sbt> coverage
sbt> test
sbt> coverageReport

doesn't re-generate the coverage report but this one does:

sbt> clean
sbt> coverage
sbt> test
sbt> coverageReport

e.g The following sequence will always generate the same coverage report (i.e. the report that was generated the first time around):

sbt> coverage
sbt> test
sbt> coverageReport

here I change one of my test files and again run:

sbt> coverage
sbt> test
sbt> coverageReport
Chitterlings answered 7/4, 2017 at 13:9 Comment(4)
is the project open source so that we can have a look? I never realised such behaviour. I usually only run coverage on CI, and I always do clean because I'm a bit paranoid on that :)Separatist
From my experience that is exactly the problem with scoverage - during coverage instrumentation it only notices parts of code affected in some way. If you clean it will measure coverage on whole code. If you repeat measurement after that, it will only measure on... I guess parts touched by incremental compilation.Kowalski
@Separatist We keep test coverage at 100% so I want to make sure that I won't break the build before committing. The project isn't open source but you can replicate that behaviour with any projectChitterlings
SBT compilation is incremental, Scoverage uses a sequence to identify statements it instruments. This sequence is not stored anywhere, it's being reset on every compilation. For incremental compilation different statements would reuse the same first sequence numbers (1, 2, 3, ...) and it would lead to inconsistent scoverage data. Maybe it would be possible to store and reuse the sequence in subsequent builds, but nobody tried it.Storer
F
0

I am going to copy comments posted on this question:

By Mateusz Kubuszok:

From my experience that is exactly the problem with scoverage - during coverage instrumentation it only notices parts of code affected in some way. If you clean it will measure coverage on whole code. If you repeat measurement after that, it will only measure on... I guess parts touched by incremental compilation.

By Grzegorz Slowikowski:

SBT compilation is incremental, Scoverage uses a sequence to identify statements it instruments. This sequence is not stored anywhere, it's being reset on every compilation. For incremental compilation different statements would reuse the same first sequence numbers (1, 2, 3, ...) and it would lead to inconsistent scoverage data. Maybe it would be possible to store and reuse the sequence in subsequent builds, but nobody tried it.

Flowered answered 7/4, 2017 at 13:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.