C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
TestNG @BeforeSuite AnnotationTill now, we read about the @BeforeTest and @AfterTest which have control over the particular @BeforeSuite: The @BeforeSuite annotated method is executed before the execution of all the test cases defined in the Generally, @BeforeSuite is used when we have different URLs to run your test cases. Environment variables are set in a @BeforeSuite annotated method so that before executing all the test cases, you need to load all the environment variables for your framework, and then it starts executing your test cases. The @BeforeSuite annotated method is given as the first priority, so it is executed before all the other test methods. Let's understand the @BeforeSuite annotated method through an example. Step 1: Open the Eclipse. Step 2: We create three modules of loan, i.e., Car_loan.java, Home_loan.java, and Personal_loan.java. Car_loan.java package com.TheDeveloperBlog; import org.testng.annotations.Test; public class Car_loan { @Test public void car_loan() { System.out.println("Car Loan"); } } Home_loan.java package com.TheDeveloperBlog; import org.testng.annotations.Test; public class Home_loan { @Test public void home_loan() { System.out.println("Home Loan"); } } Personal_loan.java package com.TheDeveloperBlog; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; public class Personal_loan { @Test public void personal_loan() { System.out.println("Personal Loan"); } @BeforeSuite public void before_suite() { System.out.println("First method"); } } Step 3: Create testng.xml file to configure classes. testng.xml file We created three modules of loan, i.e., Car loan, Personal loan, and Home loan. Their class files are configured in the testng.xml file. The @BeforeSuite annotated method is defined in the Personal_loan.java file which means that @BeforeSuite annotated method, i.e., before_suite() is executed first before all the test methods available in configured classes in the XML file. According to the testng.xml file, TestNG will first execute the before_suite() method and then TestNG will follow the sequence of Step 4: Run the testng.xml file. Right click on the testng.xml, and then move down to the Run As, click on the 1 TestNG Suite. Output
Next TopicTestNG Annotations
|