Add "start-stop" goals for the spring-boot-maven-plugin
See original GitHub issueIn order to run integration tests for a spring boot app, you can use the workaround described in #667.
There is a more detailed article here.
But in some cases, this approach can’t be used. One example would be running Cucumber tests.
I have two use cases: The first one uses maven. I want to start my spring-boot app, run some Cucumber tests, then stop the spring-boot app, everything within Maven.
Another use case would be: Having the spring-boot running in my IDE and then run the Cucumber tests also from the IDE, by connecting to the already running app.
I wouldn’t like to have the deployment phase hardcoded into the test class as in the example article. This is because (as described in the second use case) if I already have an instance of the application running, I should be able to run my cucumber test directly from my IDE, without starting another instance. I’d like to decouple the deployment step and testing step, as they don’t really belong together.
Another reason for having the start-stop approach in the maven plugin is that the method of running the tests described in the article doesn’t help me, because Cucumber has to be run using a @RunWith(@Cucumber.class)
junit annotation, and the spring boot need the @RunWith(SpringJUnit4ClassRunner.class)
annotation. And we can’t use two @RunWith
annotations on one test class.
I managed to start my spring boot app using maven, like this:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>boot.Main</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<id>boot-run</id>
<goals>
<goal>run</goal>
</goals>
<phase>pre-integration-test</phase>
<configuration>
<fork>true</fork>
</configuration>
</execution>
</executions>
</plugin>
But after the boot-app is started, the maven build is blocked… As soon as you press Ctrl+C, to stop the tomcat, the build resumes.
Issue Analytics
- State:
- Created 9 years ago
- Comments:32 (20 by maintainers)
okay so those who are interested to try this out are welcome to use a local build of my gh-2525 branch branch. This should work out-of-the-box as long as forking is not enabled (more on that later). For instance, the following configuration should run your integration tests
We are using a property to trigger an auto-configuration that registers a MBean who serves two purposes:
ApplicationReadyEvent
(see gh-2638)ApplicationContext
).So what’s the problem with fork? The short answer is that I don’t know. Since we are using JMX, we can also start the process with the necessary system properties to expose the MbeanServer on a given port and connect to that port to invoke the exact same operations. But for some reasons it does not work while the same code outside of the maven plugin works. I am sure I am missing something.
If you want to try it out (code unpolished), check the gh-2525-remote.
@snicoll it worked thanks … using the BOM was a silly error from my side cheers .