0

I have come across a very strange phenomenon:

Our CI system (Jenkins with Maven and Sonar plugin) runs Maven test builds on checkins (works fine) and runs nightly builds with Sonar intgration (ran fine until last week). Now the nightly build compiles and runs the test (all green) and calls the Sonar plugin. After the static analysis the Sonar start JaCoCo to measure the until test coverage; when JaCoco runs the unit tests (again), a lot of them run through as expected, but then first one test throws an exception (not thrown in the usual runs) about creating an object that is already there, and some tests later the whole process freezes in the try to rollback a transaction (normally not rolled back).

No component has been updated, and no suspicious code changes have been done around the failing tests.

Does anybody know, how JaCoCo treats the unit tests differently and how to solve this problem?

Uwe Allner
  • 3,399
  • 9
  • 35
  • 49
  • Can you please provide your version of the Java plugin, your SonarQube version and the log of the analysis where it is failing ? Thanks. – benzonico Jun 03 '14 at 13:30

1 Answers1

1

First read my FAQ

You are saying:

Now the nightly build compiles and runs the test (all green) and calls the Sonar plugin... When JaCoco runs the unit tests (again)

What does sonar plugin do? Main purpose is to collect test reports, including jacoco and send it to sonar. It can run tests for you and immediately collect data too, but this is not what you expect I think. If you want just to send test coverage to sonar server, run your sonar plugin with sonar.dynamicAnalysis=reuseReports parameter. It won't run your tests again.

Your tests run good without sonar plugin and then sonar plugin breaks them? It could be possible if your tests require additional java parameters (-Dcom.stackoverflow=somevalue) that you don't pass to sonar plugin, or may be you use special maven profile (-Psomeprofile) and don't do that when calling sonar plugin

By the way:

when JaCoco runs the unit tests (again)

Jacoco can not run tests. Your unit tests have to be started with jacoco plugin/agent so jacoco will save *.exec file for you. If you see this file(most commonly in target dir) you have jacoco running correctly at least.

Community
  • 1
  • 1
ZuzEL
  • 12,768
  • 8
  • 47
  • 68
  • As it turned out the problem was caused by my boss, who set the configuration of the HSQLDB from mem to file and inadvertently checked this in; so the second run of the tests found a non empty DB and crashed after a while. But your answer (and your FAQ especially) contain a lot of information to better configure our Sonar installation, so I accept it. Thanks a lot! – Uwe Allner Jun 05 '14 at 06:36