jUnit:如何过滤在多个套件中找到的测试
当 jUnit 运行包含多个“子套件”的测试套件时,是否可以过滤在不同套件中找到的测试以使它们仅运行一次?我正在开发一个包含许多数据库集成测试的项目,因此最好只运行一次,以使其更快。
考虑这个“主套件”:
@RunWith(Suite.class)
@SuiteClasses
({
ModuleASuite.class,
ModuleBSuite.class,
// More suites...
})
public class MainSuite
{}
以及这些“子套件”:
@RunWith(Suite.class)
@SuiteClasses
({
TestA1.class,
TestA2.class,
//... More tests only related to ModuleA
SomeTestUsedByManyModules.class
})
public class ModuleASuite
{}
@RunWith(Suite.class)
@SuiteClasses
({
TestB1.class,
TestB2.class,
//... More tests only related to ModuleB
SomeTestUsedByManyModules.class
})
public class ModuleBSuite
{}
当前,当使用 jUnit 4.4(使用 Eclipse 或 Ant)运行 MainSuite
时,它会运行 SomeTestUsedByManyModules
两次。我怎样才能让它只运行一次?我想过制作自己的 Runner 但也许有一个更简单的解决方案吗?
When jUnit runs a test suite containing multiple "sub suites", is it possible to filter tests found in different suites as to make them run only once? I'm working on a project with many database integration tests so it's desirable run these only once as to make it quicker.
Consider this "main suite":
@RunWith(Suite.class)
@SuiteClasses
({
ModuleASuite.class,
ModuleBSuite.class,
// More suites...
})
public class MainSuite
{}
And these "sub suites":
@RunWith(Suite.class)
@SuiteClasses
({
TestA1.class,
TestA2.class,
//... More tests only related to ModuleA
SomeTestUsedByManyModules.class
})
public class ModuleASuite
{}
@RunWith(Suite.class)
@SuiteClasses
({
TestB1.class,
TestB2.class,
//... More tests only related to ModuleB
SomeTestUsedByManyModules.class
})
public class ModuleBSuite
{}
Currently when running MainSuite
using jUnit 4.4 (using Eclipse or Ant) it runs SomeTestUsedByManyModules
twice. How can I make it run only once? I thought of making my own Runner but maybe there's an easer solution for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道如何使用 @RunWith(Suite) 来做到这一点,但是不同的方法怎么样? ClassPathSuite 允许您提供测试名称模式,以避免需要手动列出所有名称模式。
I don't know how to do it with @RunWith(Suite), but what about a different approach? ClassPathSuite lets you provide test name patterns to avoid the need to list them all out manually.