【问题标题】:mvn testng can't run test suite while Idea canmvn testng 无法运行测试套件,而 Idea 可以
【发布时间】:2016-01-16 14:02:31
【问题描述】:

我有一个像这样的 testNg 套件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="BlahServerSuite">
    <test name="Creating Customer Test">
        <classes>
        <class name="com.node.service.scripts.server.CustomerTest" />
        </classes>
    </test>
</suite>

当我从 IDE 运行它时它运行正常。但是当我尝试使用“mvn test”从控制台执行它时,出现以下错误:

  [TestNGClassFinder] Warning: Can't link and determine methods of class com.node.service.scripts.server.CustomerTest

我的 pom 看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                        <suiteXmlFiles>
                            <suiteXmlFile>src/testNode/java/com/testnode/service/scripts/server/serversuite.xml</suiteXmlFile>
                        </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <groupId>groupId</groupId>
    <artifactId>testNode</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
    ....

该项目由几个模块组成。即使 pom 文件位于 modul2(以及测试)中,我仍然需要在 pom 中设置套件文件的完整路径,否则 mvn 根本看不到测试套件。 这里可能是什么情况,我应该怎么看?

【问题讨论】:

    标签: maven automated-tests testng


    【解决方案1】:

    可能是您使用非标准位置作为测试源。如果您在某些设置中隐式添加它们,它可能仍然可以在 IDE 中使用。因此,请尝试改用src/test,或者尝试将您添加到src/testNode 以测试源。例如,您可以使用 build-helper-maven-plugin 进行操作。像这样:

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>add-test-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>src/testNode</source>
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-19
      • 1970-01-01
      • 1970-01-01
      • 2020-11-17
      • 2020-03-15
      • 2015-12-21
      • 2011-12-24
      • 1970-01-01
      相关资源
      最近更新 更多