Maven Cobertura and Package without running Unit Tests Twice - java

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?

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.

Related

Unit test fails on build from Intellij but passes from terminal

I have a big java project. Using maven to automate the build and manage dependencies and JUnit for the unit testing.
When i'm running mvn clean install from Intellij the build fails because of one unit test that fails.
The test succeeds when ran manually.
Also, executing mvn clean install from the terminal succeeds. (all tests pass)
I'm not sure where to look for the problem here.
Thanks!

Failing to call single junit test method using maven from command line

I am using command like mvn -q -Dtest=MyJUnitTestClassName#runSingleTest testas per maven & junit documentation it should run ONLY the runSingleTest test method. but problem is all tests are running.
I am using maven3 and junit4.
mvn -q -Dtest=MyJUnitTestClassName#runSingleTest test
Try quotes around your class and test (i.e. -Dtest="MyJUnitTestClassName#runSingleTest"). I use Maven 3.3 and JUnit 4 and the syntax you listed works for me, but that behavior sounds similar to issues with some versions of the SureFire plugins.
Run a single test method with maven

How to run test cases with the spring-boot framework

I downloaded and successfully ran this project:
https://github.com/spring-guides/gs-accessing-data-mongodb
I noticed it has some test cases on the file:
https://github.com/spring-guides/gs-accessing-data-mongodb/blob/master/complete/src/test/java/hello/CustomerRepositoryTests.java
To run the main application from the command line, I do:
$ ./mvnw spring-boot:run
Now, I would like to know what command do I need to execute in order to run the test cases?
Thanks!
You just need to run this command to run your tests.
mvn test
https://spring.io/guides/gs/testing-web/ can give you more information about testing.

What's the difference between -DskipTests and -Dmaven.test.skip=true

I was trying to build hive-0.13.
When using -Dmaven.test.skip=true, it will not build the test jars but it will check test dependency.
When using -DskipTests, it will not build the test jars and also not check test dependency.
What's the difference between -DskipTests and -Dmaven.test.skip=true?
Maven docs:
-DskipTests compiles the tests, but skips running them
-Dmaven.test.skip=true skips compiling the tests and does not run them
Also this one might be important
maven.test.skip is honored by Surefire, Failsafe and the Compiler
Plugin
There is a third, related option described here: https://stackoverflow.com/a/21933970/3169948
"maven.test.skip.exec=true" the tests get compiled, but not executed.
So the complete set of test options for Maven would be:
-DskipTests ==> the tests get compiled, but not executed.
-Dmaven.test.skip.exec=true ==> the tests get compiled, but not executed (exactly the same as -DskipTests).
-Dmaven.test.skip=true ==> doesn't compile or execute the tests.

Unable to run integration test without compiling (with failsafe)

I currently try to run an integration test with maven failsafe, like described in here: reference link .
For this, I got 3 Modules: datamodule, datamodule2 and testmodule (all covered by a parent pom). testmodule depends on the two other modules. It got an test in src/test/java/ named MyTestIT.java. If I try to run the test with mvn clean test failsafe:integration-test, everything runs fine, but if I only run mvn failsafe:integration-test, it does not work. Does somebody know how it's this way?
If I try to run the test with surefire, for example with mvn test -Dtest=MyTestIT, it says it can't find MyTestIT in datamodule, and I need to set -DfailIfNoTests=false. If I try to run it with mvn test --pl testmodule, it says it can't find the dependencies (this only happens when they are not installed, but I don't want to call install everytime I run a test).
Is there any way of setting this in a pom, either in the parent pom or in the project pom? Or any other way of saying to maven "only run the integration tests, use the right dependencies and do not install everything"?

Categories

Resources