0

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

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

使用 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按字母顺序排列的方法。

4

2 回答 2

0

我想到了。或者至少我通过降级到Maven 2.2.1. 由于某种原因,它似乎Maven 3.0.x不遵守该参数。runOrder但是不需要专门的 v3,所以降级对我来说很好。不过还是很奇怪。

于 2013-06-21T23:53:02.457 回答
0

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

我也在运行带有故障安全 2.15、并行关闭等的修昔底德……配置几乎相同,只是目标 java 版本是 1.6。

于 2013-06-21T17:28:03.070 回答