【问题标题】:Automatically starting/stopping web server for frontend tests为前端测试自动启动/停止 Web 服务器
【发布时间】:2013-11-22 02:26:09
【问题描述】:

现在,我开始通过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>

但这并没有帮助

【问题讨论】:

    标签: java maven testing configuration embedded-tomcat-7


    【解决方案1】:
            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>
    

    【讨论】:

    • 请指定这些语句的放置位置?
    • 几个问题。您使用哪个 Maven 版本?在配置中 - url 和服务器在我的编辑器中是红色的,这里似乎不允许使用元素。第二个:如何指定测试是集成?使用的类名:SimpleViewControllerSeleniumTest
    猜你喜欢
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多