【问题标题】:pom.xml to recognize main class to generate testng xmlpom.xml 识别主类生成 testng xml
【发布时间】:2017-05-12 06:42:08
【问题描述】:

我正在使用一个主类,它将在运行时创建一个 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>

【问题讨论】:

  • 这是一种奇怪的方法。最好建议您编写一个标准的 junit 测试方法,该方法从您的文件中读取 xml 测试配置/数据,并通过运行一系列测试来处理。

标签: testng pom.xml


【解决方案1】:

我认为问题是由于 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

【讨论】:

    猜你喜欢
    • 2011-08-07
    • 2019-08-12
    • 2016-03-15
    • 2016-08-06
    • 2014-12-13
    • 2012-12-29
    • 2011-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多