JUnit:有没有办法跳过属于测试类父级的测试?
我有两个类:
public abstract class AbstractFoobar { ... }
和
public class ConcreteFoobar extends AbstractFoobar { ... }
我有这两个类相应的测试类:
public class AbstractFoobarTest { ... }
和
public class ConcreteFoobarTest extends AbstractFoobarTest { ... }
当我运行 ConcreteFoobarTest(在 JUnit 中)时,AbstractFoobarTest 中带注释的 @Test 方法将与直接在 ConcreteFoobarTest 上声明的方法一起运行,因为它们是继承的。
有没有办法跳过它们?
I have two classes:
public abstract class AbstractFoobar { ... }
and
public class ConcreteFoobar extends AbstractFoobar { ... }
I have corresponding test classes for these two classes:
public class AbstractFoobarTest { ... }
and
public class ConcreteFoobarTest extends AbstractFoobarTest { ... }
When I run ConcreteFoobarTest (in JUnit), the annotated @Test methods in AbstractFoobarTest get run along with those declared directly on ConcreteFoobarTest because they are inherited.
Is there anyway to skip them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更新:误解了问题
AbstractFoobarTest
抽象。这样测试方法就可以了
AbstractFoobarTest
仅运行一次,当
ConcreteFoobarTest
为被执行。你将需要一个
具体子类来测试
无论如何,
AbstractFoobar
中的方法。之间
AbstractFoobartest
和ConcreteFoobarTest
。你不想要无论如何都要利用它。
Update: Misunderstood the Question
AbstractFoobarTest
abstract.That way the test methods in
AbstractFoobarTest
are only runonce, when
ConcreteFoobarTest
isexecuted. You are going to need a
concrete subclass to test the
methods in
AbstractFoobar
anyway.between
AbstractFoobartest
andConcreteFoobarTest
. You don't wantto make use of it anyway.
你实际上根本不需要
AbstractFoobarTest
因为毕竟你无法创建抽象类的实例,所以,你仍然会依赖你的具体类来测试你的抽象类。这意味着,您最终将使用
ConcreteFoobarTest
来测试抽象类中的 API。因此,你将得到这样的:-You really don't need
AbstractFoobarTest
in the first place because after all you can't create an instance of the abstract class, so, you will still rely on your concrete class to test your abstract class.That means, you will end up using your
ConcreteFoobarTest
will test the APIs from the abstract class. Thus, you will have just this:-使用进程标签将允许您遇到特定的代码体
Using process tags would allow you to run into specific bodies of code