【转】maven 自动化web应用集成测试

236 篇文章 0 订阅

web应用集成测试的时候,各位还需要启动web容器,然后打开浏览器,输入ulr,然后看到浏览器的输出吗?

下面我们用maven做到自动化!

 

 

我们利用maven的生命周期和jetty插件来实现。

 

 

下面描述下做的自动化web集成测试实现的原理。

1,在生命周期pre-integration-test启动jetty容器

2,在生命周期integration-test中测试我们写的***IT.java类

3,在post-integration-test shutdow jetty容器。

在pom.xml中加入代码如下:

<profiles> 
        <profile> 
            <id>ittest</id> 
            <build> 
                <plugins> 
                    <plugin> 
                        <groupId>org.apache.maven.plugins</groupId> 
                        <artifactId>maven-surefire-plugin</artifactId> 
                        <executions> 
                            <execution> 
                                <id>run-integration-test</id> 
                                <phase>integration-test</phase> 
                                <goals> 
                                    <goal>test</goal> 
                                </goals> 
                                <configuration> 
                                    <includes> 
                                        <include>**/*IT.java</include> 
                                    </includes> 
                                </configuration> 
                            </execution> 
                        </executions> 
                    </plugin> 
                    <plugin> 
                        <groupId>org.mortbay.jetty</groupId> 
                        <artifactId>maven-jetty-plugin</artifactId> 
                        <version>6.1.26</version> 
                        <configuration> 
                            <contextPath>/</contextPath> 
                            <stopPort>9966</stopPort> 
                            <stopKey>stop-jetty-for-it</stopKey> 
                            <connectors> 
                                <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"> 
                                    <port>6211</port> 
                                </connector> 
                            </connectors> 
                        </configuration> 

                        <executions> 
                            <execution> 
                                <id>start-it-jetty</id> 
                                <phase>pre-integration-test</phase> 
                                <goals> 
                                    <goal>run</goal> 
                                </goals> 
                                <configuration> 
                                    <daemon>true</daemon> 
                                </configuration> 
                            </execution> 
                            <execution> 
                                <id>stop-it-jetty</id> 
                                <phase>post-integration-test</phase> 
                                <goals> 
                                    <goal>stop</goal> 
                                </goals> 
                            </execution> 
                        </executions> 
                    </plugin> 
                </plugins> 
            </build> 
        </profile> 
    </profiles>

 然后就可以编写测试用例了

 

 步骤如下:

1,定义一个以此命名的****IT的测试类(integration test缩写), 在里面华丽的写好你的测试逻辑。

再此不举例了,主要一个思路可以用httpclint来实现里面的测试代码。 

2,然后 执行 mvn clean post-integration-test -Pittest

好了 就可以看到我们测试用例是否通过。

建议:以上的代码可以加入到父类的pom中,以后继承此父pom后,只需要按以上2步,就可以做到web应用测试自动化了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值