创建2个类,一个before和after,一个正常的test,在创建testng.xml文件,在idea中运行testng.xml,可以看出suite执行一次,@BeforeSuite 和 @AfterSuite在该套件的所有测试都运行在注释的方法之前,仅运行一次。@BeforeTest在每一次Test是,都进行支持
public class DBConfig {
@BeforeSuite()
public void beforeSuite() {
System.out.println("@BeforeSuite");
}
@AfterSuite()
public void afterSuite() {
System.out.println("@AfterSuite");
}
@BeforeTest()
public void beforeTest() {
System.out.println("@BeforeTest");
}
@AfterTest()
public void afterTest() {
System.out.println("@AfterTest");
}
}
public class TestDBConnection {
@Test
public void runOtherTest1() {
System.out.println("@Test - runOtherTest1");
}
@Test
public void runOtherTest2() {
System.out.println("@Test - runOtherTest2");
}
}
testng.xml配置如下:
<suite name="TestAll">
<!-- @BeforeTest -->
<test name="case1">
<classes>
<class name="myTest" />
<class name="TestDBConnection" />
<class name="DBConfig" />
</classes>
</test>
<!-- @AfterTest -->
<!-- @BeforeTest -->
<test name="case2">
<classes>
<class name="TestDBConnection" />
<class name="DBConfig" />
</classes>
</test>
<!-- @AfterTest -->
</suite>
//原文出自【易百教程】,商业转载请联系作者获得授权,非商业请保留原文链接:https://www.yiibai.com/testng/configuration-annotations.html
网友评论