java - 自动启动/停止前端测试的 Web 服务器

标签 java maven testing configuration embedded-tomcat-7

现在,我通过maven单独启动嵌入式tomcat:

mvn tomcat7:run

然后运行 ​​mvn test 目标。 我的问题是我可以配置 maven 以便自动执行此操作吗? tomcat 必须在所有测试运行之前启动,然后停止。

使用了tomcat插件的以下maven配置:

        <plugins>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <path>/SpringMvcExample</path>
                <url>http://localhost:8080/manager/text</url>
                <server>tomcat7</server>
            </configuration>
        </plugin>
    </plugins>

我已尝试将插件配置更新为:

    <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.1</version>
        <configuration>
            <path>/SpringMvcExample</path>
            <url>http://localhost:8080/manager/text</url>
            <server>tomcat7</server>
        </configuration>
        <executions>
            <execution>
                <id>start-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>
    </plugin>

但这并没有帮助

最佳答案

        attach tomcat:run to pre-integration-test
        attach tomcat:shutdown to post-integration-test
Below is the code snippet. 
    <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.1</version>
       <executions>
          <execution>
            <id>tomcat-run</id>
            <goals>
              <goal>run-war-only</goal>
            </goals>
            <phase>pre-integration-test</phase>
                <configuration>

                    <fork>true</fork> 
                </configuration>

           </execution>
           <execution>
            <id>tomcat-shutdown</id>
            <goals>
              <goal>shutdown</goal>
            </goals>
            <phase>post-integration-test</phase>
          </execution>
        </executions>
      </plugin>

关于java - 自动启动/停止前端测试的 Web 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19886816/

相关文章:

java - 过滤 JSON 响应 Java Spring - RESTful 服务

java - 为什么这个 ArrayList 将所有内容存储在第一个索引中?如何在 JSP 中从该数组列表动态加载图像 url?

java - 清除Java应用程序的缓存

java - 无法删除 slf4j 依赖项

maven - 不能做 mvn tomcat :deploy because of http response 405

python - 使用 selenium 保持登录帐户

java - 如何在 Cucumber jvm 场景之间传递变量和值

maven - 如何解读 M2E 中的生命周期映射对话框?

ruby-on-rails - 目录 : integration test fail

testing - 场景测试是连续单元测试的组吗?