【问题标题】:mvn unable to execute testNG classes in custom location from terminalmvn 无法从终端在自定义位置执行 testNG 类
【发布时间】:2019-01-28 08:10:55
【问题描述】:

给定一个文件夹结构:

theProject/src/com/myclass/tests/api/APITest

包声明在哪里:

package com.myclass.tests.api;

它使用来自 testng 的 @Test。

在 pom.xml 中,我已经包含了构建部分:

<build>
    <testSourceDirectory>${project.basedir}/</testSourceDirectory>
     <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.19.1</version>
          <configuration>
                    <includes>
                        <include>**/*Test.class</include>
                        <include>**/*test.class</include>
                        <include>src/com/myclass/tests/api/*Test.class</include>
                    </includes>
                </configuration>
        </plugin>
    </plugins>
  </build>

我尝试在 theProject 文件夹(pom.xml 所在的文件夹)中执行以下命令。

mvn test -Dtest=com.myclass.tests.api.*

但结果给出:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project theProject: No tests were executed!  (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]

我应该如何从 mvn 运行测试?

【问题讨论】:

  • 你能分享你的 pom.xml 吗?

标签: java maven testng


【解决方案1】:

我不认为

 <testSourceDirectory>${project.basedir}/</testSourceDirectory>

那就是你想要的。

试试

<testSourceDirectory>${project.basedir}/src</testSourceDirectory>

改为。

推理:Maven没有找到文件夹结构

/com/myclass/tests/api

这将是${project.basedir} 中的包结构(您的测试)的结果,因此它找不到您的测试并失败。需要处理额外的 src 文件夹。

【讨论】:

    猜你喜欢
    • 2012-05-20
    • 1970-01-01
    • 1970-01-01
    • 2017-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-28
    • 2018-08-15
    相关资源
    最近更新 更多