自动启动/停止前端测试的Web服务器 [英] Automatically starting/stopping web server for frontend tests

查看:160
本文介绍了自动启动/停止前端测试的Web服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我通过maven分别嵌入tomcat:

  mvn tomcat7:run 

然后运行 mvn test 目标。
我的问题是我可以配置maven为了自动这样做吗?
必须在所有测试运行之前启动,然后停止。



以下maven配置for tomcat plugin is used:

 < 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>
< / goal>
< / execution>
< execution>
< id> stop-tomcat< / id>
< phase> post-integration-test< / phase>
< goals>
< goal> shutdown< / goal>
< / goal>
< / execution>
< / executions>
< / plugin>

但它没有帮助

解决方案

$

  attach tomcat:run to pre-integration-test 
attach tomcat:shutdown to post-integration-test
下面是代码片段。
< plugin>
< groupId> org.apache.tomcat.maven< / groupId>
< artifactld> tomcat7-maven-plugin< / artifactId>
< version> 2.1< / version>
< executions>
< execution>
< id> tomcat-run< / id>
< goal>
< goal> run-war-only< / goal>
< / goal>
< phase> pre-integration-test< / phase>
< configuration>

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

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


Now, I start separately embedded tomcat via maven:

mvn tomcat7:run

And then run the mvn test goal. My question is can I configure maven in order to do that automatically? tomcat has to be started before all tests run, and then stopped.

The following maven configuration for tomcat plugin is used:

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

I've tried to update the plugin configuration to:

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

But it did not help

解决方案

        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>

这篇关于自动启动/停止前端测试的Web服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆