【发布时间】:2017-08-04 21:56:48
【问题描述】:
考虑以下 TestNG 套件:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name = "TestNG Examples" parallel = "false" thread-count = "1">
<test name = "TestNG Examples">
<classes>
<class name = "com.example.A"/>
<class name = "com.example.B"/>
</classes>
</test>
</suite>
由这些类组成:
package com.example;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public final class A extends AbstractTest {
@BeforeMethod
public void setUp() {
throw new RuntimeException();
}
@Test
public void test() {
}
}
和
package com.example;
import org.testng.annotations.Test;
public final class B extends AbstractTest {
@Test
public void test() {
System.out.println("B.test()");
}
}
注意B.test()是在A.test()之后执行的,两个类都有一个共同的超类:
package com.example;
import org.testng.annotations.AfterMethod;
public abstract class AbstractTest {
@AfterMethod
public final void tearDown() {
}
}
现在,如果 A 中的 @BeforeMethod 挂钩由于某种原因失败(如上例所示),则扩展相同超类 (AbstractTest) 的后续套件类将永远不会运行:
这是 Eclipse 的屏幕截图,但我在 IntelliJ IDEA 和 TeamCity 中也观察到了相同的行为。
必须满足以下先决条件才能重现此问题:
- 这两个测试应该有一个共同的祖先。
- 共同祖先应该有一个
@AfterMethod钩子。 - 正在运行的第一个测试类应该有一个失败的
@BeforeMethod挂钩。
这是预期的行为吗? 它是否记录在任何地方?
【问题讨论】:
-
我确认这个问题。您能在github.com/cbeust/testng/issues 上开票吗?
-
TestNG 是什么版本的?我尝试使用 6.11,但似乎无法重现该问题。 @juherr 你试过什么版本?
-
@KrishnanMahadevan 我使用 master 分支,但尚未更新。我只用套件文件重现了这个问题。
-
@juherr - 期望应该为
B类运行测试方法和 aftermethod,这发生在我身上。请参阅此gist,其中我创建了一个完整的示例以及断言。我在 6.11 上运行它,它可以工作。 -
@KrishnanMahadevan 我按要点回答了
标签: java unit-testing testng