简体   繁体   English

Maven:如何使用故障安全插件在jar中运行/包含类?

[英]Maven: How can I run/include a class in a jar with the failsafe plugin?

I've made my own class with an @RunWith(AllTests.class) on it for integration tests that I want to execute, but I've put it in a reusable jar. 我使用@RunWith(AllTests.class)在我自己的类上进行了要执行的集成测试,但是我将其放在了可重用的jar中。 I'm trying to tell failsafe to use it but I'm not sure how to because the documentation for includes says: 我试图告诉故障保险使用它,但是我不确定该如何使用,因为包含的文档中说:

A list of elements specifying the tests (by pattern) that should be included in testing. 指定测试中应包括的测试(按模式)的元素列表。 When not specified and when the test parameter is not specified, the default includes will be 当未指定且未指定test参数时,默认包括

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

Each include item may also contain a comma-separated sublist of items, which will be treated as multiple entries. 每个包含项还可能包含项的逗号分隔子列表,这些子列表将被视为多个条目。 This parameter is ignored if the TestNG suiteXmlFiles parameter is specified. 如果指定了TestNG suiteXmlFiles参数,则忽略此参数。

But this test runner is in the classpath, not on the filesystem. 但是此测试运行程序位于类路径中,而不位于文件系统中。 How can I tell failsafe to use my class runner and only my class runner? 如何告诉故障保险仅使用班级跑步者?

Can't you use the @RunWith annotation provided by jUnit? 您不能使用jUnit提供的@RunWith注释吗?

import com.example.YourTestRunner;

@RunWith(YourTestRunner.class)
public class SomeIntegrationTest {

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

Update 更新

Based on the comment: 根据评论:

My class isn't a test runner, but a class that uses @RunWith 我的课程不是测试跑步者,而是使用@RunWith的课程

you can use inheritance to solve the problem: 您可以使用继承来解决问题:

@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
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Maven Failsafe 插件运行 JUnit 5 集成测试? - How do I run JUnit 5 integration tests with the Maven Failsafe plugin? Maven - 如何在使用 maven-source-plugin 生成的.jar 文件中包含 jsp 文件 - Maven - How can I include jsp files in the .jar file generated using maven-source-plugin Spring 启动 maven 插件 - 如何构建可执行 jar 并包含运行它的脚本? - Spring Boot maven plugin - how do I build an executable jar and include a script to run it? 如何配置maven shade插件以在我的jar中包含测试代码? - How can I configure the maven shade plugin to include test code in my jar? 如何使用antrun插件将类作为jar文件通过Maven运行 - How to run a class as a jar file trough maven with antrun plugin 如何在Maven jar中包含测试类并执行它们? - How can I include test classes into Maven jar and execute them? 如何通过 maven-failsafe-plugin 运行基于 spring-boot 的应用程序的集成测试? - How to run integration test of a spring-boot based application through maven-failsafe-plugin? Maven failsafe插件不会运行并行测试 - Maven failsafe plugin doesn't run parallel Test Maven 不使用故障安全插件运行集成测试 - Maven does not run integration tests using failsafe-plugin Maven Thrift插件-如何包含Thrift定义? - Maven thrift plugin - How can I include thrift definitions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM