2013-04-12 24 views
1

我正在使用Maven和surefire插件來運行我的測試。我有幾個不同的測試,並運行到所有我使用相同的POM。目前所有的工作都正常,但現在我有兩個不同的屬性文件來獲取我的測試用例的一些條目,所以我想爲這兩個不同的屬性逐個運行所有這些測試用例。我的意思是我想爲它使用兩個不同的測試套件,那麼我怎樣才能管理POM? 任何幫助將不勝感激.. !!!如何在同一個項目中管理兩個不同測試套件的POM surefire插件

使用 - JDK 1.6和Maven 3.1

回答

1

如果可以啓動兩個Maven構建了一個又一個,然後嘗試類似的東西:

      <execution> 
          <id>integration-test</id> 
          <phase>integration-test</phase> 
          <goals> 
           <goal>integration-test</goal> 
           <goal>verify</goal> 
          </goals> 
          <configuration> 
           <excludes> 
             <exclude>**/test/**${dontUse}.properties</exclude> 
           </excludes> 
           <includes> 
            <include>**/test/**${use}.properties</include> 
           </includes> 
          </configuration> 
         </execution> 

並通過dontUse並將其作爲參數使用行家。或者您可以定義兩個配置文件 - 一個包含第一個配置文件,一個包含其他屬性文件 - 然後使用這兩個配置文件啓動構建。 編輯:加載屬性文件與一個單一的類,你檢查文件是否存在。無論是第一個還是第二個。 類似的東西:

public Properties load() { 
    Properties prop = new Properties(); 
    try { 
     InputStream in; 
     in = getClass().getResourceAsStream("first.properties"); 
     if (in == null) 
      in = getClass().getResourceAsStream("second.properties"); 
     prop.load(in); 
     in.close(); 
     return prop; 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    return prop; 
} 

+2

故障保護比神火在集成測試階段使用更好 – artbristol

+0

YES,完全同意 –

+0

感謝揚的回答,它的工作的。但是我怎麼能只做一次maven構建呢。 Surefire可以嗎? –

相關問題