简体   繁体   English

如何配置Maven在启动tomcat服务器后运行测试?

[英]How to configure Maven to run tests after it starts tomcat server?

When I run my maven project, it starts with the tests, and they all fail because tomcat server hasn't started yet and the war hasn't been deployed? 当我运行我的maven项目时,它从测试开始,并且全部失败,因为tomcat服务器尚未启动并且战争尚未部署? How can I configure maven to when testing to: 测试以下内容时如何配置Maven:

Start the server/application --> then run the tests --> then stop the server 启动服务器/应用程序->然后运行测试->然后停止服务器

You can use Tomcat Maven Plugin to run tomcat during build. 您可以在构建过程中使用Tomcat Maven插件运行tomcat。 Try following configuration: 尝试以下配置:

<build>
    <plugins>
        <!-- excludes tests that require application -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <excludes>
                    <exclude>**/TomcatPingTest.java</exclude>
                </excludes>
            </configuration>
        </plugin>
        <!-- starts tomcat before test execution and stops after-->
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <executions>
                <execution>
                    <id>run-tomcat</id>
                    <phase>pre-integration-test</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
                <execution>
                    <id>stop-tomcat</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>shutdown</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <fork>true</fork>
                <port>5555</port>
                <path>/app</path>
            </configuration>
        </plugin>
        <!-- runs tests -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.12</version>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <includes>
                    <include>**/TomcatPingTest.java</include>
                </includes>
            </configuration>
        </plugin>
    </plugins>
</build>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM