[英]TestNG: All subsequent Test classes are skipped when @BeforeClass method fails?
When I run the tests via a testNG xml file and there is an exception within the @BeforeClass method of one of the Test classes, then all subsequent Test classes are skipped by TestNG .当我通过 testNG xml 文件运行测试并且其中一个 Test 类的 @BeforeClass方法中存在异常时,TestNG 将跳过所有后续的 Test 类。
When I change the annotation in the TestBase class to @BeforeSuite for example, then all tests are run , even if there is an exception in on of the @BeforeClass methods.例如,当我将 TestBase 类中的注释更改为@BeforeSuite 时,即使 @BeforeClass 方法中存在异常,也会运行所有测试。
When you run the xml file, complete RunAllTestClasses02 class is skipped.运行 xml 文件时,将跳过完整的 RunAllTestClasses02 类。
testNG xml file: testNG xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<suite name = "MiscSuite">
<test name = "MiscTest">
<classes >
<class name="drkthng.misc.RunAllTestClasses01" />
<class name="drkthng.misc.RunAllTestClasses02" />
</classes>
</test>
</suite>
TestBase class with a @BeforeClass method:带有 @BeforeClass 方法的 TestBase 类:
public abstract class RunAllTestClassesBase {
@BeforeClass
public void beforeClass() {
// do something that all Test classes will need
}
}
Test class that throws Exception within @BeforeClass method:在@BeforeClass 方法中抛出异常的测试类:
public class RunAllTestClasses01 extends RunAllTestClassesBase {
@BeforeClass
public void beforeClass() {
Assert.assertTrue(false);
}
@Test
public void Test01() {
Assert.assertTrue(true);
}
}
This was a bug in Testng. 这是Testng中的一个错误。 solved in 6.9.5.
在6.9.5中解决。 Please upgrade.
请升级。
Where i am going wrong and what i am missing please help我哪里出错了,我错过了什么,请帮忙
Try to add @AfterClass(alwaysrun = true)
or/and @AfterMethod(alwaysrun=true)
as by default they are skipped if either BeforeClass or BeforeMethod are not completed. 尝试添加
@AfterClass(alwaysrun = true)
或/和@AfterMethod(alwaysrun=true)
,因为默认情况下,如果未完成BeforeClass或@AfterMethod(alwaysrun=true)
,则会跳过它们。
The documentation on testNG Configuration Failures, Policy, and alwaysRun explains whether/when configuration failures cause listener methods ( alwaysRun
and other listeners) to be skipped, failure policies and best practices. 有关testNG配置失败,策略和alwaysRun的文档说明了配置失败是否/何时导致跳过侦听器方法(
alwaysRun
和其他侦听器),失败策略和最佳实践。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.