如何避免;org.testng.TestNGException:测试<;[a-t1,a-t3]>;找不到。”;?

如何避免;org.testng.TestNGException:测试<;[a-t1,a-t3]>;找不到。”;?,testng,maven-surefire-plugin,testng.xml,Testng,Maven Surefire Plugin,Testng.xml,当运行testng xml时,它只运行指定的测试(即下面示例中的a-t1、a-t3) 有关更多信息,请参阅中的“测试标记”部分中的“运行”testnames </plugins> [...] <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifac

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

有关更多信息,请参阅中的“测试标记”部分中的“运行”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>

[...]
org.apache.maven.plugins
maven surefire插件
3.0.0-M3
[...]
src/test/resources/suite.xml
测试名
a-t1,a-t3
[...]
[...]
当使用这些标记从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)
[RemoteTestNG]检测到TestNG版本7.0.0
org.testng.TestNGException:
找不到测试。
位于org.testng.testng.parseSuite(testng.java:315)
在org.testng.testng.initializeSuitesAndJarFile(testng.java:350)上
位于org.testng.testng.initializeEverything(testng.java:980)
位于org.testng.remote.support.RemoteTestNG6_12.initialize(RemoteTestNG6_12.java:22)
位于org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:98)
位于org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
位于org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
为了避免上述异常,我应该注释掉surefire插件的属性标签

是否可以避免出现异常,而不必注释掉surefire插件的属性标签?

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

测试名
a-t1,a-t3
尝试在没有suiteXml标记的情况下运行,如下所示:
org.apache.maven.plugins
maven surefire插件
3.0.0-M3
测试名
surefirePlugin.TestmyMethod,surefirePlugin.TestmyMethod1
测试
maven编译器插件
1.8
1.8

为什么要在
surefire
插件下包含
testnames
属性?为什么不从
testng.xml
运行测试呢?我需要从Jenkins运行单个测试,所以使用“testnames”属性。使用此
从testng.xml运行单个测试这里,单个测试指的是testng xml中的单个测试标记,而不是单个方法。是的,您可以将其放入测试标记中,并通过传递
-testnames
命令行参数从jenkins运行该标记<代码>将只运行在与这些名称之一匹配的标记中定义的测试。来自官方tetsng网站,评论suiteXmlFiles标记对我不起作用。是否有其他方法可以避免此问题,而不必注释掉suiteXmlFiles标记?
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>