本文介绍了如何使用TestNG SkipException?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何有效使用TestNG 抛出新的SkipException()?有人有例子吗?

How do I use TestNG throw new SkipException() effectively? Does anyone have an example?

我尝试在测试方法开始时抛出此异常,但它炸毁了拆解,设置,方法等,并且具有附带条件通过导致一些(不是全部)后续测试也被跳过而造成损坏,并在TestNG HTML报告上显示一堆垃圾。

I tried throwing this exception at the start of a test method but it blows up the teardown, setup, methods, etc. , and has collateral damage by causing a few (not all) of the subsequent tests to be skipped also, and shows a bunch of garbage on the TestNG HTML report.

我使用TestNG运行我的单元测试,我已经知道如何使用@Test批注中的选项来禁用测试。我希望我的测试在报告中显示为存在,但不计入最终结果。换句话说,如果有一个@Test注释选项可以跳过测试,那就太好了。这样一来,我就可以将测试标记为已忽略的排序,而不必使测试从所有测试的列表中消失。

I use TestNG to run my unit tests and I already know how to use an option to the @Test annotation to disable a test. I would like my test to show up as "existent" on my report but without counting it in the net result. In other words, it would be nice if there was a @Test annotation option to "skip" a test. This is so that I can mark tests as ignored sortof without having the test disappear from the list of all tests.

在之前,必须在@BeforeXXX中抛出 SkipException @Test运行了吗?

Is "SkipException" required to be thrown in @BeforeXXX before the @Test is ran? That might explain the wierdness I am seeing.

推荐答案

是的,我的怀疑是正确的。在我使用类并行时,在@Test中抛出异常是行不通的,在@BeforeTest中也不会抛出异常。如果这样做,则异常将破坏测试设置,并且TestNG报告将在所有相关的@Configuration方法中显示异常,甚至可能导致后续测试失败而不会被跳过。

Yes, my suspicion was correct. Throwing the exception within @Test doesn't work, and neither did throwing it in @BeforeTest, while I am using parallel by classes. If you do that, the exception will break the test setup and your TestNG report will show exceptions within all of the related @Configuration methods and may even cause subsequent tests to fail without being skipped.

但是,当我将其扔到@BeforeMethod中时,它可以正常工作。很高兴我能弄清楚。 建议该类可在任何@Configuration注释方法中使用,但是关于我正在做的事情不允许我这样做。

But, when I throw it within @BeforeMethod, it works perfectly. Glad I was able to figure it out. The documentation of the class suggests it will work in any of the @Configuration annotated methods, but something about what I am doing didn't allow me to do that.

@BeforeMethod
public void beforeMethod() {
    throw new SkipException("Testing skip.");
}

这篇关于如何使用TestNG SkipException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 05:05