gpt4 book ai didi

java - 根据条件运行特定的单元测试

转载 作者:太空宇宙 更新时间:2023-11-04 12:15:34 25 4
gpt4 key购买 nike

我有一个测试类,其中包含蓝色和非蓝色设备的测试用例。如果设置了参数 isBlue,那么它应该只运行那些带有 @Blue 注释的测试用例。我不确定如何实现这个特定的注释来实现此功能。

public class TestClass {

boolean isBlue = false;

@Before
public void setUp () {
isBlue = MyApplication.instance().isBlue();
}

@Test
public void testA () { ... }

@Test @Blue
public void testB() { ... }
}

在此示例中,如果 isBluetrue 那么它应该只运行 testB() 否则它应该运行所有测试用例

最佳答案

看看 JUnit 运行程序。 Nice explanation of runners

您可以创建自己的运行程序,该运行程序将在 BlockJUnit4ClassRunner 上扩展。

您可以覆盖

@Override
protected List<FrameworkMethod> getChildren() {
// scan test class for methonds annotated with @Test
}

另外按设置了自定义注释的方法进行过滤,并且还设置了应用程序中的属性。

关于java - 根据条件运行特定的单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39447324/

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