pom.xml识别主类生成testng xml

时间:2016-12-28 01:43:47

标签: testng pom.xml

使用主类,它将在运行时创建一个testng xml。主类将根据excel中设置的标志(是/否)创建运行测试方法(来自testng xml)。 如果我运行主类,则需要正确创建testng xml。但是如果我使用pom xml对maven build(test)做同样的事情,它不会考虑我的主类,它开始运行testng xml中的测试。下面是我的pom 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>

1 个答案:

答案 0 :(得分:0)

我认为问题是因为maven surefire插件是你的超级pom的一部分(见here)。默认情况下,Surefire插件启用了以下过滤器,以帮助它找到具有测试方法的类(参见here

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

我猜你有一个或多个名字以Test结尾的java类,这就是为什么surefire插件基本上也在执行它们的原因。你可能想要 利用surefire插件的excludesFile属性,并排除执行java类。有关详细信息,请参阅here