gpt4 book ai didi

java - JUnit : Is there a way to skip a test belonging to a Test class's parent?

转载 作者:行者123 更新时间:2023-11-30 05:06:23 24 4
gpt4 key购买 nike

我有两门课:

public abstract class AbstractFoobar { ... }

public class ConcreteFoobar extends AbstractFoobar { ... }  


这两个类我有相应的测试类:

public class AbstractFoobarTest { ... }

public class ConcreteFoobarTest extends AbstractFoobarTest { ... }


当我运行 ConcreteFoobarTest (在 JUnit 中)时,AbstractFoobarTest 中带注释的 @Test 方法将与直接在 ConcreteFoobarTest 上声明的方法一起运行,因为它们是继承的。

有什么办法可以跳过它们吗?

最佳答案

更新:误解了问题

  1. 使AbstractFoobarTest抽象。这样测试方法就可以了AbstractFoobarTest 仅运行一次,当 ConcreteFoobarTest 为被执行。你将需要一个具体子类来测试无论如何,AbstractFoobar 中的方法。
  2. 或者只是删除继承之间 AbstractFoobartestConcreteFoobarTest。你不想要无论如何都要利用它。

关于java - JUnit : Is there a way to skip a test belonging to a Test class's parent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4970721/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com