0
0
Selenium Javatesting~20 mins

Test groups in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Test Groups Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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");
    }
}
ARunning testA\nRunning testC
BRunning testB\nRunning testC
CRunning testA\nRunning testB\nRunning testC
DRunning testC
Attempts:
2 left
💡 Hint
Only tests tagged with the 'smoke' group run when that group is selected.
assertion
intermediate
2: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
AassertTrue(executedTests.contains("testB") || executedTests.contains("testC"));
BassertFalse(executedTests.contains("testA"));
CassertEquals(executedTests.size(), 3);
DassertTrue(executedTests.containsAll(Arrays.asList("testB", "testC")) && executedTests.size() == 2);
Attempts:
2 left
💡 Hint
Check that only the expected tests ran and no extra tests.
🔧 Debug
advanced
2: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?
ABecause the test method is private
BBecause the test is in the 'integration' group but the suite runs only the 'unit' group
CBecause the test method name does not start with 'test'
DBecause the test method is missing @Test annotation
Attempts:
2 left
💡 Hint
Check the group names in the test and in the suite XML.
framework
advanced
2: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?
AAnnotate fast tests with @Test(groups = {"smoke"}) and slow tests with @Test(groups = {"regression"}), then run groups selectively
BPut all tests in one group and run them all every time
CUse @Test(enabled = false) for slow tests and enable them manually
DCreate separate test classes for smoke and regression but do not use groups
Attempts:
2 left
💡 Hint
Groups help run subsets of tests based on speed or purpose.
🧠 Conceptual
expert
2: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?
ATestNG runs all tests in the order they appear in the class regardless of groups
BTests in both groups run but tests with multiple groups run last
CAll tests in 'fast' and 'database' groups run; order is not guaranteed unless specified
DOnly tests in the intersection of 'fast' and 'database' groups run
Attempts:
2 left
💡 Hint
Groups select tests, but order depends on configuration or annotations.