Spring Boot Maven plugin run goal doesn't invoke tests - spring

Following command doesn't run any of my tests :
mvn spring-boot:run
whereas plain old mvn test does.
I have added these annotations to the tests :
#RunWith(SpringRunner.class)
#SpringBootTest
I do not see any relevant information on the plugin documentation pages, either here or here

Spring boot maven plugin
Requires a Maven project to be executed. Requires dependency
resolution of artifacts in scope: test. Since version: 1.1. Binds by
default to the lifecycle phase: validate. Invokes the execution of the
lifecycle phase test-compile prior to executing itself.
More details
Maven lifecycles:
validate compile test ...
More details
To sum up: spring-boot:run only compiles tests and execute maven validate phase. One of the possible solutions to execute tests before start of the application: mvn test spring-boot:run

Related

Exclude testng tests while building in jenkins

I have a test which consists of both junit test and testng tests. It works fine when i run 'mvn test' from parent pom, but testng tests fail while building in jenkins. I need a way to skip testng tests from running in jenkins.
You said you use jenkins so i assume that you are using maven plugin :
Have you tried to skip test cases in your Maven run? Use the code below in maven properties section of maven plugin:
maven.test.failure.ignore=true
Or
please use below code in properties section of maven plugin to skip the test cases
skipTests=true
Hope this helps
It's better to set it up via runtime in Jenkins' job configuration:
Invoke Top Level Maven -> Advanced.
Add maven.test.skip=true
Once the tests are OK, just remove this line.
You can disable test execution in runtime as well:
mvn -Dmaven.test.skip=true

Maven build - run an application then perform JUnit tests

As part of my build process, I would like maven to start a program and then execute JUNIT tests in the same phase, which is the mvn test phase.
I am using Spring Boot as well as the Spring Boot Maven plugin. As you know Spring boot has an embedded tomcat container. So I can just run my application on this tomcat server by just running as an application in eclipse.
For example when I run mvn test, I would like my application to run FIRST and then have the tests executed.
I have seen the exec-maven plugin being used and that you specify the phase in the maven build cycle that you want the application to run. The earliest phase that it allows you to specify is the test phase.
But I'm not sure if the Application will run immediately before the tests?
How do I specify in my POM file that I want the application to run BEFORE the test phase?

Disable the integration test phase in pom.xml

There is a open source project called Apache Any23 , the instructions to checkout and build it are listed at the link below.
https://any23.apache.org/build-src.html
I am unable to to do a mvn clean install by following the instructions because the integration test phase gets invoked by the maven invoker plugin , I have user -Dskipstests etc , but the invoker plugin still gets invoked , I need you to bypass/suppress the integration test phase and the surefire plugin tests and do a successful build.
It this requires a pom.xml change, I need you to send me the updated file and let me know what changes were made.
Thanks
Does the project use the Failsafe plugin to run the integration tests? If so, try to skip them this way:
mvn install -DskipTests
However, since skipTests is also supported by the Surefire Plugin, this will have the effect of not running any tests. If, instead, you want to skip only the integration tests being run by the Failsafe Plugin, you would use the skipITs property instead:
mvn install -DskipITs
If you absolutely must, you can also use the maven.test.skip property to skip compiling the tests. maven.test.skip is honored by Surefire, Failsafe and the Compiler plugins.
mvn install -Dmaven.test.skip=true
Read more about this here.

How can I atomically run mvn tests (without rebuilding source code)?

I want to run a maven project lifecycle starting, and ending, with the unit tests.
How can I skip recompilation and re-resolution of dependencies and only run the test phase?
If you start maven by calling a phase it will execute all lifecycle phases up to the one you are calling. For example, when calling
mvn test
all the phases before the test lifecycle phase will be execute too: the project will be validated, sources and resources will be generated and processed, sources will be compiled, the same will happen to test sources and resources and finally unit tests will be run.
But you can also call the plugin goal that is bound to a lifecycle phase. In the case of the test phase the bound goal is surefire's test mojo. So you could call
mvn surefire:test
and no other lifecycle phase will be executed.
You can find the goals bound to each phase depending on the package type here.
You can run :
mvn surefire:test
Build your own lifecycle, or run the tests with something besides Maven (Ant, Gradle, your IDE, command-line JUnit runner, ...). That's the kind of restriction you live with when you're using Maven.

Can I run post processing on my maven integration test results if there are test failures?

I want to extend a maven2 POM to run some post processing on my integration test results. I added a java:exec plugin and bound it to the post-integration-test phase.
All is fine when the tests pass but if I get any test failures then the post processing isn't executed.
Question: Is there an option to force a task, regardless of the results of the integration test phase?
Our POM was using the Surefire plugin to execute the integration tests but it looks like that was a mistake. The Failsafe plugin is intended to address this issue. From the documentation:
If you use the Surefire Plugin for running tests, then when you have a test failure, the build will stop at the integration-test phase and your integration test environment will not have been torn down correctly. The Failsafe Plugin is used during the integration-test and verify phases of the build lifecycle to execute the integration tests of an application. The Failsafe Plugin will not fail the build during the integration-test phase thus enabling the post-integration-test phase to execute.
http://maven.apache.org/plugins/maven-failsafe-plugin/

Resources