【问题标题】:Maven: How can I run/include a class in a jar with the failsafe plugin?Maven:如何使用故障安全插件在 jar 中运行/包含一个类?
【发布时间】:2013-10-26 11:45:16
【问题描述】:

我已经创建了自己的类,上面带有@RunWith(AllTests.class),用于我想要执行的集成测试,但我把它放在了一个可重复使用的罐子里。我试图告诉故障安全使用它,但我不确定如何使用,因为the documentation for includes 说:

指定应包含在测试中的测试(按模式)的元素列表。当未指定和未指定测试参数时,默认包含将是

<includes>
 <include>**/IT*.java</include>
 <include>**/*IT.java</include>
 <include>**/*ITCase.java</include>
</includes>

每个包含项目还可能包含一个以逗号分隔的项目子列表,它们将被视为多个条目。 如果指定了 TestNG suiteXmlFiles 参数,则忽略此参数。

但是这个测试运行器在类路径中,而不是在文件系统中。如何告诉故障安全使用我的班级跑步者并且只使用我的班级跑步者?

【问题讨论】:

  • 不清楚你所说的“test runner是什么意思。如果你的意思是Runner的实例,你需要在依赖部分添加jar scope=test
  • @Augusto 哪个依赖部分?插件的?它不是Runner 的实例,而是带有@RunWith(AllTests.class) 注释的Pojo

标签: java maven junit maven-failsafe-plugin


【解决方案1】:

不能使用jUnit提供的@RunWith注解吗?

import com.example.YourTestRunner;

@RunWith(YourTestRunner.class)
public class SomeIntegrationTest {

    @Test
    public void simpleTest() {
       // given, when, then
    }
}

更新

根据评论:

我的班级不是测试运行程序,而是使用@RunWith 的班级

你可以使用继承来解决这个问题:

@RunWith(SomeTestRunner.class)
@Ignore("Not a real test class because it does not contain any @Test methods, but needed to keep surefire happy")
public class ParentTest {
    // this is the reusable class that is in the jar file
}


public class SomeIntegrationTest extends ParentTest {

    @Test
    public void simpleTest() {
       // given, when, then
    }
}

【讨论】:

  • 我说错了。我的班级不是测试运行者,而是使用@RunWith 的班级。
  • 这对我不起作用,但很难弄清楚原因。 -X 给我的信息比我需要的多 100 倍,所以我不知道为什么它没有找到这个 SomeIntegrationTest
  • 我猜你已经验证了你已经将 jar 添加为依赖项。接下来,您必须确保要扩展的类位于 src/main/java 文件夹的子文件夹中(而不是 src/test/java,因为此文件夹中的任何类都将仅用于测试,而不是打包在罐子)。
猜你喜欢
  • 1970-01-01
  • 2013-11-12
  • 2012-09-15
  • 1970-01-01
  • 1970-01-01
  • 2016-02-15
  • 1970-01-01
  • 1970-01-01
  • 2013-05-23
相关资源
最近更新 更多