Maven+Surefire+Testng 的顺序 - BeforeClass、BeforeTest、Test、Test、AfterTest、AfterClass
我期望得到以下输出:
Running TestSuite
[DEBUG] beforeClass
[DEBUG] beforeTest
[DEBUG] test
[DEBUG] afterTest
[DEBUG] beforeTest
[DEBUG] test
[DEBUG] afterTest
[DEBUG] afterClass
但相反,这实际上发生了。注意 2 个问题:BeforeClass after BeforeTest 运行。其次,Before/AfterTest 运行一次。
Running TestSuite
[DEBUG] beforeTest
[DEBUG] beforeClass
[DEBUG] test
[DEBUG] test
[DEBUG] afterClass
[DEBUG] afterTest
这是代码。
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class TestNgAnnoTest {
@BeforeClass
public void beforeClass(){
System.out.println("beforeClass");
}
@BeforeTest
public void beforeTest(){
System.out.println("beforeTest");
}
@Test
public void test1(){
System.out.println("test");
}
@Test
public void test2(){
System.out.println("test");
}
@AfterTest
public void afterTest(){
System.out.println("afterTest");
}
@AfterClass
public void afterClass(){
System.out.println("afterClass");
}
}
对于任何对工具版本感兴趣的人: java macosx/1.6.0_22,mvn:2.2.1,surefire 2.6,testng 5.14.2
I expected the following output:
Running TestSuite
[DEBUG] beforeClass
[DEBUG] beforeTest
[DEBUG] test
[DEBUG] afterTest
[DEBUG] beforeTest
[DEBUG] test
[DEBUG] afterTest
[DEBUG] afterClass
But instead, this actually happens. Notice 2 problems: BeforeClass runs after BeforeTest. Second, Before/AfterTest runs once.
Running TestSuite
[DEBUG] beforeTest
[DEBUG] beforeClass
[DEBUG] test
[DEBUG] test
[DEBUG] afterClass
[DEBUG] afterTest
Here's the code.
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class TestNgAnnoTest {
@BeforeClass
public void beforeClass(){
System.out.println("beforeClass");
}
@BeforeTest
public void beforeTest(){
System.out.println("beforeTest");
}
@Test
public void test1(){
System.out.println("test");
}
@Test
public void test2(){
System.out.println("test");
}
@AfterTest
public void afterTest(){
System.out.println("afterTest");
}
@AfterClass
public void afterClass(){
System.out.println("afterClass");
}
}
For anyone curious about tool versions:
java macosx/1.6.0_22, mvn: 2.2.1, surefire 2.6, testng 5.14.2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
愚蠢的我。将 After/BeforeTest 与 After/BeforeMethod 混淆。
替换 After/BeforeTest 会产生正确的执行顺序。
Stupid me. Confused After/BeforeTest with After/BeforeMethod.
Replacing After/BeforeTest produced the correct exec ordering.
正确的。 @BeforeTest/@AfterTest 包装标签,而不是测试方法。
Correct. @BeforeTest/@AfterTest wrap a tag, not a test method.