How to run unit tests only when running "maven clean install" and Sonar?

I had the following configuration for my Jenkins work: First clean and create a maven project, then do unit tests and static analysis: clean install sonar:sonar The problem was that install and sonar:sonar performed unit tests that effectively doubled the build time .

I fixed this by changing clean install sonar:sonar to clean install -DskipTests and starting Sonar using the Jenkins sonar plugin. Now the device tests were performed only once, and the sonar showed the results, but Jenkins no longer knew about the tests.

My guess is that Jenkins only looks in the correct reports folder after the build, and not after Sonar (this is the action after build).

+6
source share
2 answers

First you can run clean install -DskipTests , and then add the second build step of maven sonar:sonar . Testing (and full sonar analysis) will be performed during the build phase, and the results of the correct results can be collected by Jenkins subsequently.

+11
source

As you said, Sonar is a compilation step. Sonar requires that the assembly be complete and pass all the tests before it is launched, otherwise the things that it does have no meaning.

Sonar runs tests using the toolkit (cobertura, if I remember correctly), which provides code coverage for the tests.

So, you need to complete the installation (or at least compile and test) before launching Sonar, and then Sonar will re-run the tests using its own goals.

+2
source

Source: https://habr.com/ru/post/897690/


All Articles