How to run embedded Tomcat 9 inside Maven 3 for integration testing purposes?

后端 未结 1 1817
情歌与酒
情歌与酒 2021-01-21 20:41

I am trying to run embedded Tomcat 9 inside Maven 3 for integration testing purposes. I was led to cargo-maven2-plugin by other SO answers.

So, attempting t

相关标签:
1条回答
  • 2021-01-21 21:01

    After trying many permutations, this finally worked for me:

            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <version>1.7.9</version>
                <configuration>
                    <container>
                        <systemProperties>
                            <myvar1>${myEnvVar}</myvar1>
                            <myvar2>... stuff ...</myvar2>
                        </systemProperties>
                        <containerId>tomcat9x</containerId>
                        <zipUrlInstaller>
                            <url>https://repo.maven.apache.org/maven2/org/apache/tomcat/tomcat/9.0.29/tomcat-9.0.29.zip</url>
                        </zipUrlInstaller>
                    </container>
                    <deployables>
                        <deployable>
                            <groupId>org.codehaus.cargo</groupId>
                            <artifactId>simple-war</artifactId>
                            <type>war</type>
                            <location>path/to/myapp.war</location>
                            <properties>
                                <context>myapp</context>
                            </properties>
                        </deployable>
                    </deployables>
                    <executions>
                        <execution>
                            <id>start-server</id>
                            <phase>pre-integration-test</phase>
                            <goals>
                                <goal>start</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>stop-server</id>
                            <phase>post-integration-test</phase>
                            <goals>
                                <goal>stop</goal>
                            </goals>
                        </execution>
                    </executions>
                </configuration>
            </plugin>
    

    Use the failsafe plugin to automatically run the Integration Tests between the start and stop:

                <plugin>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.21.0</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>integration-test</goal>
                                <goal>verify</goal>
                            </goals>
                            <configuration>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
    
    0 讨论(0)
提交回复
热议问题