Well actually from some of the earlier comments it's actually that people don't
want to run their (long running) tests twice...
All I have being pointing out is that there is a MAJOR falicy with thinking that
if my tests pass when I'm measuring code coverage then everything works.
If you only run the tests once, and that once is with instrumented code, then
you may have bugs that you don't know about.
The most major source of such bugs is unintended synchronization. The JVM can
cache any non-volatile values between synchronization points. Instrumentation
records into a coverage results map each time a code path is covered... which
results in increased synchronization, as each time is passes a branch point
(either for an NPE, or an explicit branch in your code) it has to update the
coverage map, which involves synchronized access to that map (because there may
be multiple threads). The net result is that variable changes from other
threads are more visible when your code is instrumented.
Now as the JVM spec only says that the JVM is allowed to cache (for performance
improvement) the excess synchronization is not incorrect... in fact your code
should function correctly irrespective of whether the JVM has cached the value
or not... 9 times out of 10 though people assume that the JVM is not caching
things on them, so that is why you need to run the tests without coverage.
Another thing you should do is run the tests with a different JVM (ideally a
different vendor: JRockit or IBM's JVM) as these have different optimization and
caching strategies (all legal under the JVM spec)
In my experience, there is a diminishing return here though, and 80% of these
kind of bugs will be found if you run on just one JVM with and without coverage
(i.e. 2 runs through your test suite)
With 6 runs through your tests suite (Sun, IBM, JRockit, Sun + emma, Sun +
cobertura, and any JVM on a different architecture) you're pretty safe... but
the effort involved in setting up such a testing suite can sometimes be such
that the 80:20 rule comes into play and we don't bother.
Yes I agree that hudson should report the source of the test results... perhaps
it should count reruns on the same test as partial scores... so if
TestMyClass.smokeTest()
has run 3 times, we count that as one test, and each run passing run counts as
1/3 towards the passing count, failing runs count as 1/3 towards the failing
count, skipped runs count as 1/3 towards the skipped count, etc
To my view, there is nothing to be gained in splitting the reporting of these
multiple tests as you need to know if this test passed with Sun and no coverage
before you wonder if the failure with Sun and cobertura is something that should
be looked into (for synchronization/threading issues)
In short, if any test is failing you need to find out why and fix it (either by
having the test not run if code coverage is active, or by fixing the bug in your
code or fixing the bug in your test)
(The only reason emma got dragged in is that somebody quoted the FAQ entry I
wrote while pushing the emma-maven-plugin out the door... so that I could write
the m2 support for emma into the coverage plugin that i've been working on for
some time now)
I'm having the same issue. I'm wondering if you can tweak the pom to only
execute the tests once, which should be done anyway, in order to reduce the
build time.
Currently I'm using the maven goals "install findbugs:findbugs
cobertura:cobertura" in my hudson project, but would like to reduce that to
"install" only. If this would be documented somewhere, then this bug is also
obsolete, imho.