How to only run unit tests once when running "maven clean install" and Sonar?
Asked Answered
W

2

6

I had the following configuration for my Jenkins job: First clean and build the maven project, then run the unit tests and static analysis: clean install sonar:sonar The problem was that install and sonar:sonar each ran the unit tests which effectively doubled the build time.

I fixed this by changing clean install sonar:sonar to clean install -DskipTests and running Sonar using the Jenkins sonar plugin. Now the unit tests ran only once and sonar showed the results, but Jenkins didn't know about the tests anymore.

My guess is that Jenkins is only looking at the surefire-reports folder after building, not after Sonar (which is a post-build action).

Wadsworth answered 20/9, 2011 at 14:26 Comment(0)
B
11

You could just run clean install -DskipTests first and then add a second maven build step sonar:sonar. The tests (and complete sonar analysis) will be run during the build phase, and the surefire results can be collected by jenkins afterwards.

Bilodeau answered 20/9, 2011 at 15:41 Comment(0)
D
2

As you said, Sonar is a post compile step. Sonar requires that the build be complete and pass all of it's tests before it can run, otherwise the things it does don't make any sense.

Sonar runs the tests with instrumenting (cobertura if I remember correctly), which gives the code coverage for the tests.

So, you need to do install (or at least compile & test) before Sonar runs, and then Sonar reruns the tests with instrumenting for it's own purposes.

Dongdonga answered 20/9, 2011 at 14:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.