2013-06-20 127 views
0

我有一個使用JUnit運行測試用例的Selenium/Thucydides項目。 在Eclipse中使用JUnit運行時,我可以使用@FixMethodOrder按字母順序運行測試。這工作正常,但是當我使用mvn verify在Maven中運行測試時,測試是隨機運行的。使用Maven按字母順序運行硒/ Thucydides JUnit測試

我看到你可以在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方法是按字母順序排列。

回答

0

<runOrder>alphabetical</runOrder>按我的預期工作。

我也運行Thucydides with failsafe 2.15,並行關閉等等...配置幾乎相同,只有目標java版本是1.6。

0

我想通了。或者至少我解決了它通過降級到Maven 2.2.1。 看來由於某種原因,Maven 3.0.x不遵守runOrder參數。 但特別不需要v3,所以降級對我來說很好。 雖然還是很奇怪。