【发布时间】:2016-02-02 07:10:31
【问题描述】:
我正在使用 TestNG 在 java 中编写测试。
我想在类文件中使用条件跳过或忽略所有类方法。
在 ruby 中,我关注了这个How to skip certain tests with Test::Unit
在java中我该怎么做?
【问题讨论】:
我正在使用 TestNG 在 java 中编写测试。
我想在类文件中使用条件跳过或忽略所有类方法。
在 ruby 中,我关注了这个How to skip certain tests with Test::Unit
在java中我该怎么做?
【问题讨论】:
如果假设不成立,您可以在测试中抛出SkipException,并且该机制足够灵活,甚至可以将测试标记为已跳过或失败。 This article 展示了如何以声明的方式将这种方法集成到您的测试套件中。基本上你用@Assumes注释方法并有一个自定义IInvokedMethodListener。
或者(我不鼓励这样做,但这是一个选项),如果您可以确定要静态跳过的内容,您可以动态生成 XML 规范并运行它。
【讨论】:
另一种解决方案是使用IAnnotationTransformers,然后像使用@Test(enabled = false) 一样禁用测试。
public void transform(ITest annotation, Class testClass,
Constructor testConstructor, Method testMethod) {
if (...determine if the test should be disabled) {
annotation.setEnable(false);
}
}
【讨论】:
你可以使用注解@Test(enabled = false)忽略测试方法
【讨论】: