testng的annotations运行顺序为:
@BeforeSuite
@BeforeTest
@BeforeClass
@BeforeMethod
@AfterMethod
@AfterClass
@AfterTest
@AfterSuite
如果测试用例父类 和子类同时有相同的标签,before遵循从外而内的顺序,即先运行父类方法,再运行子类方法。
after则遵循从内而外的顺序,即先运行子类的方法,再运行父类方法,输出如下:
10:31:03,013 INFO ATest:13 - CaseBase>>>>>>beforeSuite
10:31:03,017 INFO ATest:17 - CaseBase>>>>>>beforeTest
10:31:03,021 INFO ATest:18 - class testcase.harbor.ATest>>>@BeforeClass
10:31:03,023 INFO ATest:29 - CaseBase>>>@BeforeMethod
10:31:03,024 INFO ATest:14 - class testcase.harbor.ATest>>>@BeforeMethod
10:31:03,027 INFO ATest:22 - class testcase.harbor.ATest>>>test1
10:31:03,028 INFO ATest:30 - class testcase.harbor.ATest>>>afterMethod
10:31:03,029 INFO ATest:25 - CaseBase>>>>>>afterMethod
10:31:03,029 INFO ATest:26 - class testcase.harbor.ATest>>>@AfterClass
10:31:03,030 INFO ATest:21 - CaseBase>>>>>>afterTest