1

我已经@RunWith(AllTests.class)为我想要执行的集成测试创建了自己的类,但我把它放在了一个可重复使用的 jar 中。我试图告诉故障安全使用它,但我不确定如何使用,因为包含的文档说:

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

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

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

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

4

1 回答 1

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
    }
}
于 2013-10-17T20:31:23.067 回答