Which annotation is used to group test methods in TestNG?

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.

Reference links:

https://www.javaguides.net/p/top-java-libraries.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top