0

运行 testng xml 时,它只运行指定的测试(即,下面示例中的 a-t1、a-t3)。

有关更多信息,请参阅https://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html中的“在测试标签中运行 'testnames'”部分。

</plugins>
    [...]
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>3.0.0-M3</version>
        <configuration>
          [...]
          <suiteXmlFiles>
            <file>src/test/resources/suite.xml</file>
          </suiteXmlFiles>
          <properties>
            <property>
              <name>testnames</name>
              <value>a-t1,a-t3</value>
            </property>
          </properties>
          [...]
        </configuration>
      </plugin>
    [...]
</plugins>

当使用这些标签从 Eclipse 运行单个测试时,出现异常。

[RemoteTestNG] detected TestNG version 7.0.0
org.testng.TestNGException: 
The test(s) <[a-t1,a-t3]> cannot be found.
    at org.testng.TestNG.parseSuite(TestNG.java:315)
    at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:350)
    at org.testng.TestNG.initializeEverything(TestNG.java:980)
    at org.testng.remote.support.RemoteTestNG6_12.initialize(RemoteTestNG6_12.java:22)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:98)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

为了避免上述异常,我应该注释掉surefire插件的属性标签。

有没有办法避免异常而不必注释掉surefire插件的属性标签?

<properties>
  <property>
    <name>testnames</name>
    <value>a-t1,a-t3</value>
  </property>
</properties>
4

1 回答 1

0
try running without suiteXml tags as follow:

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M3</version>
                <configuration>
<!--                    <suiteXmlFiles> -->
<!--                        <file>src/test/resources/testng.xml</file> -->
<!--                    </suiteXmlFiles> -->
                    <properties>
                        <property>
                            <name>testnames</name>
                            <value>surefirePlugin.TestmyMethod,surefirePlugin.TestmyMethod1</value>
                        </property>
                    </properties>
                    <goal>test</goal>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
于 2019-09-18T16:13:18.750 回答