【问题标题】:Separate Selenium tests from build process将 Selenium 测试与构建过程分开
【发布时间】:2012-07-27 06:09:28
【问题描述】:

我有一个对你们来说可能非常微不足道的问题,我只是想确保我掌握了这个概念。 我已经做了很多研究和阅读 (SO post),我还是有点困惑,所以我向您求助专家!

在下面的文章中,作者提到了一种常见做法,即在构建时将 selenium 测试与单元测试分开。他们说 selenium 测试不应该在每个构建上运行,它们应该在 CI 服务器上运行,而不是作为 maven 构建的一部分,因此他们将 maven 配置为跳过 selenium 测试,然后在集成阶段运行。

我有点明白其中的原因,但我不太熟悉构建生命周期以及为什么必须按照作者的方式进行设置。

是否有人愿意提供一个简单的解释(或提供阅读材料),说明您为什么要执行这些文章中提到的事情?我开始大量使用硒,并希望更好地理解这些概念。如果这是微不足道的,再次抱歉,我不是在征求辩论、争论或投票。

非常感谢!

http://www.weblogism.com/item/334/integration-tests-with-cucumber-jvm-selenium-and-maven http://www.lagerweij.com/2011/08/24/setting-up-selenium-with-maven http://blog.tfnico.com/2007/09/continous-web-testing-with-selenium_16.html http://developershood.blogspot.com/2009/10/using-selenium-and-maven-for-junit.html

【问题讨论】:

    标签: maven selenium build continuous-integration


    【解决方案1】:

    分离并只运行单元测试的原因是:

    1. 需要在 硒测试之前运行单元测试 - 以简化故障推理。
    2. 这些类型的测试需要在 Maven 插件配置中进行不同的设置 - 并行测试运行、排序、系统属性、JVM 选项等。
    3. Selenium 测试是端到端的,需要大量的配置和部署工作、重置应用程序状态(清除数据库、启动和停止应用服务器)——这些工作在所有开发和暂存环境中都不容易完成

    Maven 有一组用于分离集成测试步骤的阶段,还有一些配置文件允许在一个地方收集 selenium 测试配置。

    这是我们使用 selenium 进行端到端测试的示例(解压缩并运行脚本以从头开始设置数据库、启动应用服务器、运行测试、停止应用服务器、验证和报告测试结果):

    <profile>
        <id>selenium</id>
        <dependencies>
            <dependency>
                <groupId>com.thenewmotion</groupId>
                <artifactId>msp-solveconnector</artifactId>
                <version>${project.version}</version>
                <classifier>sql-install</classifier>
                <type>zip</type>
                <scope>test</scope>
            </dependency>
        </dependencies>
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>unpack-dependencies</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>unpack-dependencies</goal>
                                </goals>
                                <configuration>
                                    <includeGroupIds>com.thenewmotion</includeGroupIds>
                                    <includeArtifactIds>msp-solveconnector</includeArtifactIds>
                                    <includeClassifiers>sql-install</includeClassifiers>
                                    <includeTypes>zip</includeTypes>
                                    <includes>**/*.*</includes>
                                    <outputDirectory>${project.build.directory}</outputDirectory>
                                    <overWriteReleases>false</overWriteReleases>
                                    <overWriteSnapshots>true</overWriteSnapshots>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>sql-maven-plugin</artifactId>
                        <dependencies>
                            <dependency>
                                <groupId>mysql</groupId>
                                <artifactId>mysql-connector-java</artifactId>
                                <version>5.1.16</version>
                            </dependency>
                        </dependencies>
                        <executions>
                            <execution>
                                <id>create-db</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>execute</goal>
                                </goals>
                                <configuration>
                                    <driver>com.mysql.jdbc.Driver</driver>
                                    <url>jdbc:mysql://localhost</url>
                                    <username>${msp.db.user}</username>
                                    <password>${msp.db.password}</password>
                                    <orderFile>ascending</orderFile>
                                    <fileset>
                                        <basedir>${project.build.directory}/db</basedir>
                                        <includes>
                                            <include>1_drop_database.sql</include>
                                            <include>2_create_database.sql</include>
                                            <include>3_create_tables.sql</include>
                                            <include>4_create_views.sql</include>
                                            <include>5_create_foreign_keys.sql</include>
                                            <include>6_data.sql</include>
                                        </includes>
                                    </fileset>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.mortbay.jetty</groupId>
                        <artifactId>jetty-maven-plugin</artifactId>
                        <configuration>
                            <stopKey>foo</stopKey>
                            <stopPort>8088</stopPort>
                            <connectors>
                                <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                                    <port>${msp.port}</port>
                                    <maxIdleTime>60000</maxIdleTime>
                                </connector>
                            </connectors>
                        </configuration>
                        <executions>
                            <execution>
                                <id>start-jetty</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                                <configuration>
                                    <daemon>true</daemon>
                                </configuration>
                            </execution>
                            <execution>
                                <id>stop-jetty</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>2.12</version>
                        <configuration>
                            <systemPropertyVariables>
                                <msp.user>${msp.user}</msp.user>
                                <msp.password>${msp.password}</msp.password>
                                <msp.baseUrl>${msp.baseUrl}</msp.baseUrl>
                                <webdriver.type>${webdriver.type}</webdriver.type>
                                <webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
                            </systemPropertyVariables>
                            <includes>
                                <include>**/*FT.class</include>
                            </includes>
                        </configuration>
                    </plugin>
                </plugins>
            </pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>sql-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>jetty-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    </profile>
    

    【讨论】:

      【解决方案2】:

      正如我写的一篇你提到的文章,我想我应该补充一下。

      分离出硒测试还有另一个原因。 Selenium 测试缓慢。开发人员不需要需要花费数分钟才能运行的构建。他希望从他的单元测试中得到快速反馈。 Selenium 测试可能会以较低的频率运行,例如在将代码提交/推送到版本控制之前。

      出于同样的原因,您可能会在构建服务器上设置不同的构建作业,每次检查时都会运行非 UI 测试,然后可能会运行 UI 测试,或者可能以较低的频率运行(每次小时?每晚?)取决于它们运行多长时间,以及你能负担得起的基础设施类型。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-23
        • 2016-12-04
        • 2016-10-15
        • 2020-01-06
        • 1970-01-01
        相关资源
        最近更新 更多