Skip to content

Add "start-stop" goals for the spring-boot-maven-plugin #2525

@danpersa

Description

@danpersa

In 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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions