Challenge - 5 Problems
Test Groups Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of TestNG test group execution
Given the following TestNG test class with groups, what will be the output when running only the "smoke" group?
Selenium Java
import org.testng.annotations.Test; public class SampleTest { @Test(groups = {"smoke"}) public void testA() { System.out.println("Running testA"); } @Test(groups = {"regression"}) public void testB() { System.out.println("Running testB"); } @Test(groups = {"smoke", "regression"}) public void testC() { System.out.println("Running testC"); } }
Attempts:
2 left
💡 Hint
Only tests tagged with the 'smoke' group run when that group is selected.
✗ Incorrect
When running the 'smoke' group, TestNG executes tests annotated with 'smoke'. testA and testC have this group, so their print statements appear.
❓ assertion
intermediate2:00remaining
Assertion to verify only 'regression' group tests ran
You have a TestNG test suite that runs only the 'regression' group. Which assertion correctly verifies that only tests from the 'regression' group executed?
Selenium Java
List<String> executedTests = List.of("testB", "testC"); // names of executed tests
Attempts:
2 left
💡 Hint
Check that only the expected tests ran and no extra tests.
✗ Incorrect
Option D asserts that executedTests contains exactly 'testB' and 'testC' and no others, matching the 'regression' group tests.
🔧 Debug
advanced2:00remaining
Why does a test not run when included in a group?
You have this TestNG test method:
@Test(groups = {"integration"})
public void testIntegration() {
// test code
}
You run your suite with unit in your XML but testIntegration does not run. Why?
Attempts:
2 left
💡 Hint
Check the group names in the test and in the suite XML.
✗ Incorrect
TestNG runs only tests in groups specified in the suite XML. Since 'integration' is not included, testIntegration is skipped.
❓ framework
advanced2:00remaining
Best practice for grouping tests in Selenium with TestNG
Which is the best practice for organizing Selenium tests using TestNG groups to separate fast smoke tests from slower regression tests?
Attempts:
2 left
💡 Hint
Groups help run subsets of tests based on speed or purpose.
✗ Incorrect
Using groups allows selective execution of tests based on categories like speed or type, improving test suite efficiency.
🧠 Conceptual
expert2:00remaining
Impact of overlapping groups on test execution order
Consider these TestNG tests:
@Test(groups = {"fast"})
public void test1() {}
@Test(groups = {"fast", "database"})
public void test2() {}
@Test(groups = {"database"})
public void test3() {}
If you run the suite with groups fast,database , which statement about execution order is true?
Attempts:
2 left
💡 Hint
Groups select tests, but order depends on configuration or annotations.
✗ Incorrect
TestNG runs all tests belonging to any specified group. Execution order is by default the order in the class but can be changed; groups do not guarantee order.