成就梦想

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  21 随笔 :: 22 文章 :: 6 评论 :: 0 Trackbacks
        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应用测试自动化了。

 



posted on 2012-04-21 11:57 iamct 阅读(3091) 评论(0)  编辑  收藏 所属分类: 项目管理

只有注册用户登录后才能发表评论。


网站导航: