使用Maven按字母顺序运行Selenium / Thucydides JUnit测试

时间:2013-06-20 12:28:06

标签: eclipse maven selenium-webdriver junit4 thucydides

我有一个使用JUnit运行测试用例的Selenium / Thucydides项目。 在Eclipse中使用JUnit运行时,我可以使用@FixMethodOrder按字母顺序运行测试。这工作正常,但是当我使用mvn verify在Maven中运行测试时,测试是随机运行的。

我已经看到你可以在pom.xml中设置<runOrder>alphabetical</runOrder>,但它似乎也不起作用。

在使用Maven时,是否还要按字母顺序运行测试? (我知道他们不应该相互依赖,但有些人正是在这个时候,所以需要这个选项,直到我能让他们独立)

的pom.xml:

 <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.team.app</groupId>
<artifactId>Testing</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Selenium Testing</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <thucydides.version>0.9.127</thucydides.version>
    <webdriver.driver>firefox</webdriver.driver>
</properties>
<dependencies>
    <dependency>
        <groupId>net.thucydides</groupId>
        <artifactId>thucydides-core</artifactId>
        <version>${thucydides.version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.6.1</version>
    </dependency>
    <dependency>
        <groupId>net.thucydides</groupId>
        <artifactId>thucydides-junit</artifactId>
        <version>${thucydides.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.easytesting</groupId>
        <artifactId>fest-assert</artifactId>
        <version>1.4</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.15</version>
            <configuration>
              <runOrder>alphabetical</runOrder> 
              <systemPropertyVariables>
                <webdriver.driver>${webdriver.driver}</webdriver.driver>
              </systemPropertyVariables>
              <skip>true</skip>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.15</version>
            <configuration>
                <runOrder>alphabetical</runOrder> 
                <includes>
                    <include>**/*Test.java</include>
                    <include>**/Test*.java</include>
                    <include>**/When*.java</include>
                    <include>**/*TestSuite.java</include>
                </includes>
                <systemPropertyVariables>
                    <webdriver.driver>${webdriver.driver}</webdriver.driver>
                </systemPropertyVariables>                                      
                <!-- <parallel>parallel</parallel> -->
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <encoding>UTF-8</encoding>                
                <source>1.7</source>
                <target>1.7</target>                    
            </configuration>
        </plugin>
        <plugin>
            <groupId>net.thucydides.maven.plugins</groupId>
            <artifactId>maven-thucydides-plugin</artifactId>
            <version>${thucydides.version}</version>
            <executions>
                <execution>
                    <id>thucydides-reports</id>
                    <phase>post-integration-test</phase>
                    <goals>
                        <goal>aggregate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <id>maven2</id>
        <activation>
            <file>
                <missing>${basedir}</missing>
            </file>
        </activation>
        <reporting>
            <plugins>
                <plugin>
                    <groupId>net.thucydides.maven.plugins</groupId>
                    <artifactId>maven-thucydides-plugin</artifactId>
                    <version>${thucydides.version}</version>
                </plugin>
            </plugins>
        </reporting>
    </profile>
    <profile>
        <id>maven3</id>
        <activation>
            <file>
                <exists>${basedir}</exists>
            </file>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-site-plugin</artifactId>
                    <version>3.0-beta-3</version>
                    <configuration>
                        <reportPlugins>
                            <plugin>
                                <groupId>net.thucydides.maven.plugins</groupId>
                                <artifactId>maven-thucydides-plugin</artifactId>
                                <version>${thucydides.version}</version>
                            </plugin>
                        </reportPlugins>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>
<description>Project that perform automated user test on Bosted using Selenium and Thucydides</description>

JUnit的:

  @FixMethodOrder(MethodSorters.NAME_ASCENDING)
  @Story(Application.PlanModernusConfiguration.ConfigureFieldDefinitions.class)
  @RunWith(ThucydidesRunner.class)

使用按字母顺序排列的@Test方法。

2 个答案:

答案 0 :(得分:0)

<runOrder>alphabetical</runOrder>按预期方式工作。

我还运行Thucydides,故障安全2.15,并行关闭等等......配置几乎完全相同,只有目标java版本为1.6。

答案 1 :(得分:0)

我明白了。或者至少我通过降级到Maven 2.2.1来解决它。 由于某种原因,似乎Maven 3.0.x不遵守runOrder参数。 但是不要特别需要v3,所以降级对我来说很好。 虽然还很奇怪。