public class annotationzz { @Test public void f() { System.out.println("am test f-@Test"); } @BeforeMethod public void beforeMethod() { System.out.println("am before each test-@BeforeMethod"); }
@AfterMethod public void afterMethod() { System.out.println("am after each test-@AfterMethod"); }
@BeforeClass public void beforeClass() { System.out.println("am before f-1st-@BeforeClass"); }
@AfterClass public void afterClass() { System.out.println("am after all-end- @AfterClass"); }
@BeforeTest public void beforeTest() { System.out.println("am before f-@BeforeTest"); }
@AfterTest public void afterTest() { System.out.println("am after f-@AfterTest"); }
@BeforeSuite public void beforeSuite() { System.out.println("start-@BeforeSuite"); }
@AfterSuite public void afterSuite() { System.out.println("end-@AfterSuite"); }
}
Results i get is this order: -------------------------- start-@BeforeSuite am before f-@BeforeTest am before f-1st-@BeforeClass am before each test-@BeforeMethod am test f-@Test am after each test-@AfterMethod am after all-end- @AfterClass am after f-@AfterTest PASSED: f End-@AfterSuite
Query: ----------- Why is @BeforeClass executing between @BeforeTest,@BeforeMethod? "BeforeClass-The annotated method will be run only once before the first test method in the current class is invoked." So it should be executed before @BeforeTest,@BeforeMethod. What is the logic here ?
M
Replied on 05/12/2015
maybe this image of 2 test being executed help you understand it.