I have a large Maven project which has several modules in it. When I want to run a JUnit test from one module I run 'mvn -Dtest=NameOfTest test' in the directory that contains all the modules. When I run this command Maven goes through each module and tries to compile it (though it's already compiled), which involves copying a bunch of files and adds to the total time of the test. It seems that the 'test' command for the Maven surefire plugin executes all the steps up to the test. I was wondering if there is a way to execute only the test step and not bother with all the attempted compilation and copying of files.
Here is some output from before the test starts:
[INFO] [INFO] --- build-helper-maven-plugin:1.5:add-test-source (add-test-source) @ module1 --- [INFO] Test Source directory: <directory in module1 with some generated sources> added. [INFO] [INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ module1 --- [debug] execute contextualize [INFO] Copying 108 resources [INFO] Copying 1113 resources [INFO] Copying 1 resource [INFO]
It repeats this for each of the other modules. All told it takes a minute or two before it actually starts the test. Does anyone know a way to get the test to run without bothering with all the compilation beforehand? Please let me know if there's any more information I should provide.
If you want to run just a single test instead of all the tests declared in your project, create a Maven run configuration for a single test with the Maven -Dtest=TestName test command. The run configuration will be saved under the Run Configurations node.
We can run our unit tests with Maven by using the command: mvn clean test. When we run this command at command prompt, we should see that the Maven Surefire Plugin runs our unit tests. We can now create a Maven project that compiles and runs unit tests which use JUnit 5.
To skip running the tests for a particular project, set the skipTests property to true. You can also skip the tests via the command line by executing the following command: mvn install -DskipTests.
Running 'mvn clean install' will run the default build. As specified above integration tests will be ignored. Running 'mvn clean install -P integration-tests' will include the integration tests (I also ignore my staging integration tests).
If what you would like to do is to run just the test phase of the lifecycle without running all of the previous phases you could also call the goal that is bound to the test phase:
mvn surefire:test
or if you want to run just one test
mvn -Dtest=NameOfTest surefire:test
What is wrong with simply running the test from within the module the test resides in? That way, Maven will not attempt to build the other modules which you are not interested in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With