junit assume command - 我可以将它放在设置方法中以忽略所有测试吗

junit assume command - can i put it inside setup method to ignore all tests

我有一组测试用例,如果满足某些条件,我希望忽略整个文件。我可以用吗 Assume.assumeTrue(precondition); 在设置方法中确保如果前提条件为假则测试不会 运行 在整个文件中?

所以如果我有这样的设置方法:

@Before
    public void setUp() throws Exception {
        super.setUp();
     Assume.assumeTrue(1==3);//entire test file should be ignored is my hope
       //some setup stuff ...
    }

我可以希望 none 我的测试会 运行 吗?这是我的最终目标,即在满足某些条件时我可以忽略文件中的所有测试。我试过了,它似乎忽略了它们,但想要专家意见,我不希望 Assume 方法影响除了它调用的文件中的测试之外的任何其他测试。

即使我认为这不是一个好的做法,我也能理解 @Ignore 注释将一些测试放入隔离区。但我不确定是否将其调整为标志。

就是说,实现这个: https://gist.github.com/yinzara/9980184

然后使用此 @ConditionalIgnore 注释。

public class SomeTest {
  @Rule
  public ConditionalIgnoreRule rule = new ConditionalIgnoreRule();

  @Test
  @ConditionalIgnore( condition = IgnoredByTeamA.class )
  public void testIgnoredByTeamA() {
       ...
  }
}

public class IgnoredByTeamA implements IgnoreCondition {
  public boolean isSatisfied() {
    return true;
  }
}

更多详情here