TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

TestNG @BeforeGroups Annotation

TestNG @BeforeGroups Annotation with Testng Tutorial, Introduction, Testng Installation, Features of Testng, Suite Test, Testng Exception Test, Group Test, Plug with Ant, Plug with Eclipse, etc.

<< Back to TESTNG

TestNG @BeforeGroups Annotation

TestNG allows the testers to create multiple test cases into a single group through the use of attribute 'group' in the @Test annotation. We can say that TestNG groups allow you to add similar functionalities in the same group. For example, student_id, student_name, student_address are the details of a student, and all these details are added in a same group, i.e., "student details".

@BeforeGroups: The @BeforeGroups annotated method will run only once before all the test methods belonging to a specified group have been executed.

Let's understand the @BeforeGroups annotation through an example.

Step 1: Open the Eclipse.

Step 2: We create a simple java project.

Class1.java

package com.TheDeveloperBlog;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
public class Class1 
{
@BeforeGroups("IT Department")
public void before_it()
{
System.out.println("This method will be executed before the execution of IT Department group");
}
@Test
public void testcase1()
{
System.out.println("HR");
}
 @Test(groups= {"IT Department"})
public void testcase2()
{
System.out.println("Software Developer");
}
@Test(groups= {"IT Department"})
public void testcase3()
{
System.out.println("QA Analyst");
}
}

In the above, we have created the java project in which we have defined the @BeforeGroups annotated method, and in @BeforeGroups, we pass "IT Department" which means that @BeforeGroups annotated method, i.e., before_it() will be invoked before the execution of all the test methods belonging to an "IT Department" group.

Step 3: Now, we create a testng.xml file to configure the above class.

testng.xml file








 
 

Step 4: Run the testng.xml file. Right click on the testng.xml file, move the cursor down to Run As and then click on the 1 TestNG Suite.

TestNG @BeforeGroups Annotation
Next TopicTestNG Annotations




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf