6

I am running maven like this:

mvn clean cobertura:cobertura package

I am noticing that my unit tests get run twice (thus doubling my build time). Is there a way to run cobertura AND generate the package in the same command without running tests twice?

hofan41
  • 1,438
  • 1
  • 11
  • 25
  • AFAIK there is no way to do it ! – StackFlowed Oct 21 '14 at 21:15
  • possible duplicate of [double unit test reporting with hudson and maven](http://stackoverflow.com/questions/1098445/double-unit-test-reporting-with-hudson-and-maven) – 333kenshin Oct 22 '14 at 07:43
  • 333kenshin : Perhaps they might share the same root cause, however, my question is regarding command line maven in general and not regarding hudson double reporting unit tests. – hofan41 Oct 22 '14 at 18:48
  • 3
    See http://stackoverflow.com/questions/732995/running-junits-and-cobertura-with-maven – hofan41 Jan 14 '15 at 19:04

1 Answers1

3

An easy way would be to run two separate commands. In Bash it's then easy to chain them together into one line:

mvn clean cobertura:cobertura && mvn package -Dmaven.test.skip=true

The first bit:

mvn clean cobertura:cobertura

Does clean, runs the tests and generates the coverage report.

The second bit:

mvn package -Dmaven.test.skip=true

Does the packaging, but tells it not to run the tests.

The && is there so that if the first command fails, then it won't try to run the second.

John Montgomery
  • 8,868
  • 4
  • 33
  • 43
  • Be aware that this way integration tests are not executed any more! If you want integration tests `mvn clean cobertura:cobertura-integration-test` is your friend – Haphil Sep 17 '19 at 06:00