jUnit忽略基类中的@Test方法 [英] jUnit ignore @Test methods from base class
问题描述
假设我有一个名为 testFixtureA
的测试类,其中包含多种方法 testA
, testB
, testC
等,每个都带有 @Test
注释。
Let's say I have a test class called testFixtureA
with several methods testA
, testB
, testC
, etc, each with @Test
annotation.
我们现在说我将 testFixtureA
子类化为名为 testFixtureAB
我不会覆盖任何东西。 testFixtureAB
现在是空的。
Let's now say I subclass testFixtureA
into class called testFixtureAB
and I don't overwrite anything. testFixtureAB
is empty as for now.
当我从 testFixtureAB
运行测试时,方法 testA
, testB
和 testC
由测试运行器执行,因为测试运行器不区分类和基类的测试方法。
When I run tests from testFixtureAB
, methods testA
, testB
and testC
are executed by test runner because test runner doesn't distinguish between test methods from class and baseclass.
如何强制测试运行器从基类中省略测试?
How can I force test runner to leave out tests from baseclass?
推荐答案
重组您的测试类。
- 如果您不想使用基类中的测试,请不要扩展它
- 如果您需要基类中的其他功能,请将该类拆分为两个 - 测试和其他功能
这篇关于jUnit忽略基类中的@Test方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!