Java Maven:如何使用failsafe插件在jar中运行/包含类?

Java Maven:如何使用failsafe插件在jar中运行/包含类?,java,maven,junit,maven-failsafe-plugin,Java,Maven,Junit,Maven Failsafe Plugin,我用@RunWith(AllTests.class)创建了自己的类,用于我想要执行的集成测试,但我把它放在了一个可重用的jar中。我试图告诉故障保护使用它,但我不知道如何使用,因为上面说: 指定测试中应包括的测试(按模式)的元素列表。未指定和未指定测试参数时,将使用默认的includes <includes> <include>**/IT*.java</include> <include>**/*IT.java</include>

我用
@RunWith(AllTests.class)
创建了自己的类,用于我想要执行的集成测试,但我把它放在了一个可重用的jar中。我试图告诉故障保护使用它,但我不知道如何使用,因为上面说:

指定测试中应包括的测试(按模式)的元素列表。未指定和未指定测试参数时,将使用默认的includes

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

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

但是这个测试运行程序在类路径中,而不是在文件系统中。我如何告诉failsafe使用我的类运行程序而只使用我的类运行程序?

您不能使用jUnit提供的注释吗

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
    }
}
您不能使用jUnit提供的注释吗

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

还不清楚“test runner”是什么意思。如果你指的是的实例,你需要在依赖项部分添加jar,并带有插件的
scope=test
@Augusto哪个依赖项部分?它不是
runner
的实例,而是带有
@RunWith(AllTests.class)的Pojo
注释不清楚“测试运行者”是什么意思。如果您是指的一个实例,那么您需要在依赖项部分添加jar,并使用
scope=test
@Augusto哪个依赖项部分?插件的名称?它不是
Runner
的实例,而是带有
@RunWith(AllTests.class)
注释的Pojo,我说错了。我的类不是一个测试运行程序,而是一个使用
@RunWith
的类。这对我来说不起作用,但很难找出原因
-X
提供的信息比我需要的多出100倍,因此我无法理解为什么它找不到此
SomeIntegrationTest
。我猜您已经验证了您已将jar添加为依赖项。接下来,您必须确保要扩展的类位于
src/main/java
文件夹的子文件夹中(而不是
src/test/java
,因为此文件夹中的任何类都将仅用于测试,而不是打包在jar中)。我的类不是一个测试运行程序,而是一个使用
@RunWith
的类。这对我来说不起作用,但很难找出原因
-X
提供的信息比我需要的多出100倍,因此我无法理解为什么它找不到此
SomeIntegrationTest
。我猜您已经验证了您已将jar添加为依赖项。接下来,您必须确保要扩展的类位于
src/main/java
文件夹的子文件夹中(而不是
src/test/java
,因为此文件夹中的任何类都将仅用于测试,而不会打包到jar中)。