Which annotation is used to group test methods in TestNG?
A) @Test(groups = {…})
B) @Group
C) @GroupTest
D) @TestGroup
Answer:
A) @Test(groups = {…})
Explanation:
The @Test(groups = {...})
annotation in TestNG is used to group test methods. You can specify one or more groups that a test method belongs to, allowing you to run specific groups of tests together.
For example:
@Test(groups = {"group1", "group2"})
public void testMethod() {
// Test code
}
In this example, the testMethod()
belongs to both “group1” and “group2”. You can run all tests in a particular group by specifying the group name in the TestNG configuration.