2016-12-28 251 views
0

上午我正在使用一個主類,它將在運行時創建一個testng xml。主類將根據excel中設置的標誌(是/否)創建運行測試方法(來自testng xml)。 如果我運行所需的主類testng xml正在創建正確。但如果我做同樣的maven構建(測試)使用POM XML它不認爲我的主類,它開始運行在testng XML中的測試。以下是我的pom xml。pom.xml識別主類以生成testng xml

<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>CSGAPITestAutomation</groupId> 
    <artifactId>CSGAPITestAutomation</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <build> 
     <plugins> 
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.1</version> 
       <configuration> 
        <source>1.8</source> 
        <target>1.8</target> 
       </configuration> 
      </plugin> 
       <!-- Necessary for jenkins to actually run our tests --> 

      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>exec-maven-plugin</artifactId> 
       <version>1.4.0</version> 
       <executions> 
        <execution> 
        <goals> 
         <goal>java</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <mainClass>RegressionTest.GenerateTestNG</mainClass> ---> Main class file 
       </configuration> 
       </plugin> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.19.1</version> 
     <configuration> 
     <!-- <argLine>-noverify</argLine> --> 
      <useSystemClassLoader>false</useSystemClassLoader> 
      <forkMode>never</forkMode> 
      <compilerArgument>-proc:none</compilerArgument> 
      <fork>true</fork> 

     <suiteXmlFiles>         

      <suiteXmlFile>.//Automation_TestNgSuites//GenerateXML.xml</suiteXmlFile> 
      </suiteXmlFiles> 


     </configuration> 
     </plugin> 

     </plugins> 
    </build> 

    <dependencies> 
     <dependency> 
      <groupId>com.relevantcodes</groupId> 
      <artifactId>extentreports</artifactId> 
      <version>2.40.2</version> 
     </dependency>  
     <dependency> 
      <groupId>io.appium</groupId> 
      <artifactId>java-client</artifactId> 
      <version>3.3.0</version> 
     </dependency> 
     <dependency> 
      <groupId>org.testng</groupId> 
      <artifactId>testng</artifactId> 
      <version>6.8.8</version> 
     </dependency> 
     <dependency> 
      <groupId>net.sourceforge.jexcelapi</groupId> 
      <artifactId>jxl</artifactId> 
      <version>2.6.12</version> 
     </dependency> 
     <dependency> 
      <groupId>com.jayway.restassured</groupId> 
      <artifactId>rest-assured</artifactId> 
      <version>2.9.0</version> 
     </dependency> 
     <dependency> 
      <groupId>com.jayway.jsonpath</groupId> 
      <artifactId>json-path</artifactId> 
      <version>2.2.0</version> 
     </dependency> 
     <dependency> 
      <groupId>com.pojosontheweb</groupId> 
      <artifactId>monte-repack</artifactId> 
      <version>1.0</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.poi</groupId> 
      <artifactId>poi</artifactId> 
      <version>3.13</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.poi</groupId> 
      <artifactId>poi-ooxml</artifactId> 
      <version>3.13</version> 
     </dependency> 
     <dependency> 
      <groupId>org.jdom</groupId> 
      <artifactId>jdom2</artifactId> 
      <version>2.0.5</version> 
     </dependency> 
     <dependency> 
      <groupId>jaxen</groupId> 
      <artifactId>jaxen</artifactId> 
      <version>1.1.6</version> 
     </dependency> 
     <dependency> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-api</artifactId> 
      <version>1.7.21</version> 
     </dependency> 

     <!-- http://mvnrepository.com/artifact/com.jayway.restassured/json-schema-validator --> 
     <dependency> 
      <groupId>com.jayway.restassured</groupId> 
      <artifactId>json-schema-validator</artifactId> 
      <version>2.2.0</version> 
     </dependency> 
     <dependency> 
      <groupId>org.seleniumhq.selenium</groupId> 
      <artifactId>selenium-server</artifactId> 
      <version>2.53.0</version> 
     </dependency> 
     <dependency> 
      <groupId>net.lightbody.bmp</groupId> 
      <artifactId>browsermob-core-littleproxy</artifactId> 
      <version>2.1.0-beta-3</version> 
     </dependency> 
     <dependency> 
      <groupId>com.googlecode.json-simple</groupId> 
      <artifactId>json-simple</artifactId> 
      <version>1.1.1</version> 
     </dependency> 
    </dependencies> 
</project> 
+0

這是一種奇怪的方法。建議您最好編寫一個標準的junit測試方法,通過運行一系列測試從您的文件和進程讀取xml測試配置/數據。 –

回答

0

我認爲這個問題是由於Maven的萬無一失插件是你的超級POM的一部分(見here)的事實。默認情況下,神火插件啓用了以下過濾器,以幫助它找出其中有測試方法的類(見here

<includes> 
    <include>**/Test*.java</include> 
    <include>**/*Test.java</include> 
    <include>**/*TestCase.java</include> 
</includes> 

我猜測,你有一個或多個Java類的名稱以Test這是結束爲什麼surefire插件基本上也在執行它們。您可能想要 利用surefire插件的excludesFile屬性並排除Java類的執行。欲瞭解更多信息,請參閱here