Bird
Raised Fist0
Selenium Javatesting~5 mins

Test groups in Selenium Java - Cheat Sheet & Quick Revision

Choose your learning style10 modes available
Recall & Review
beginner
What is the purpose of test groups in Selenium with Java?
Test groups help organize tests into categories so you can run specific sets of tests together, like running only smoke tests or regression tests.
Click to reveal answer
beginner
How do you define a test group in TestNG for Selenium Java?
You add the groups attribute in the @Test annotation, like @Test(groups = {"smoke"}) to assign a test to the 'smoke' group.
Click to reveal answer
intermediate
How can you run only a specific test group using TestNG?
You specify the group name in the TestNG XML file under the <groups> section or use command line options to include or exclude groups.
Click to reveal answer
intermediate
What is the benefit of using test groups in large Selenium test suites?
Test groups let you run smaller, focused sets of tests quickly, like running only critical tests before a release, saving time and resources.
Click to reveal answer
beginner
Can a single test belong to multiple groups in TestNG? How?
Yes, by listing multiple group names in the groups attribute, like @Test(groups = {"smoke", "regression"}).
Click to reveal answer
Which annotation attribute is used to assign a test to a group in TestNG?
Acategory
Bpriority
Csuite
Dgroups
How do you run only the 'smoke' test group using a TestNG XML file?
AInclude <groups><run><include name="smoke"/></run></groups>
BSet <suite name="smoke"/>
CAdd <test name="smoke"/>
DUse <parameter name="group" value="smoke"/>
What happens if you exclude a group in TestNG XML?
ATests in that group run only if others fail
BTests in that group will not run
CTests in that group run first
DTests in that group run twice
Can test groups help reduce test execution time?
AYes, by running only selected groups
BNo, all tests run anyway
COnly if tests are parallel
DOnly for UI tests
Which of these is NOT a valid reason to use test groups?
ARun smoke tests separately
BOrganize tests by feature
CRun tests by priority automatically
DExclude flaky tests temporarily
Explain how test groups work in Selenium with TestNG and why they are useful.
Think about organizing tests like sorting clothes into categories before washing.
You got /4 concepts.
    Describe the steps to run only a specific test group using TestNG XML configuration.
    It's like telling a playlist to play only your favorite songs.
    You got /4 concepts.

      Practice

      (1/5)
      1. What is the main purpose of using groups in Selenium Java tests?
      easy
      A. To change the browser used in tests
      B. To organize tests into categories for selective execution
      C. To automatically generate test reports
      D. To increase the speed of the WebDriver

      Solution

      1. Step 1: Understand the role of test groups

        Test groups help organize tests into categories, making it easier to run specific sets of tests.
      2. Step 2: Identify the correct purpose

        Groups do not affect WebDriver speed, report generation, or browser choice directly.
      3. Final Answer:

        To organize tests into categories for selective execution -> Option B
      4. Quick Check:

        Test groups = Organize tests [OK]
      Hint: Groups categorize tests to run only what you need [OK]
      Common Mistakes:
      • Thinking groups speed up WebDriver
      • Confusing groups with report generation
      • Assuming groups change browser settings
      2. Which is the correct syntax to assign a test method to groups "smoke" and "regression" in TestNG?
      easy
      A. @Test(groups = {"smoke", "regression"})
      B. @Test(group = "smoke, regression")
      C. @Test(groups = "smoke, regression")
      D. @Test(groups = ["smoke", "regression"])

      Solution

      1. Step 1: Recall TestNG groups syntax

        The correct syntax uses groups = {"group1", "group2"} with curly braces and double quotes for each group.
      2. Step 2: Compare options

        @Test(groups = {"smoke", "regression"}) matches the correct syntax. Options A, B, and D misuse quotes or attribute name. @Test(groups = ["smoke", "regression"]) uses square brackets which is invalid in Java annotations.
      3. Final Answer:

        @Test(groups = {"smoke", "regression"}) -> Option A
      4. Quick Check:

        Groups use curly braces and quotes [OK]
      Hint: Use curly braces and quotes for multiple groups [OK]
      Common Mistakes:
      • Using 'group' instead of 'groups'
      • Passing groups as a single string
      • Using square brackets instead of curly braces
      3. Given the following TestNG test methods, which tests will run if you execute only the "fast" group?
      @Test(groups = {"fast"})
      public void testA() {}
      
      @Test(groups = {"slow"})
      public void testB() {}
      
      @Test(groups = {"fast", "regression"})
      public void testC() {}
      medium
      A. testA only
      B. testB only
      C. testA and testC
      D. testB and testC

      Solution

      1. Step 1: Identify tests with group "fast"

        testA has group "fast"; testC has groups "fast" and "regression"; testB has "slow" only.
      2. Step 2: Determine which tests run when "fast" group is executed

        Only tests assigned to "fast" group run, so testA and testC run; testB does not.
      3. Final Answer:

        testA and testC -> Option C
      4. Quick Check:

        Run group "fast" = testA, testC [OK]
      Hint: Run group runs all tests tagged with it [OK]
      Common Mistakes:
      • Running tests from other groups
      • Ignoring tests with multiple groups
      • Assuming only single-group tests run
      4. What is wrong with this TestNG test method if the intention is to assign it to groups "ui" and "integration"?
      @Test(groups = "ui, integration")
      public void testUIIntegration() {}
      medium
      A. Groups should be passed as an array, not a single string
      B. The method name is invalid
      C. The annotation @Test is missing parentheses
      D. Groups attribute is not supported in @Test

      Solution

      1. Step 1: Check groups attribute format

        Groups must be passed as an array of strings using curly braces, not a single comma-separated string.
      2. Step 2: Identify the error in the code

        The code uses a single string "ui, integration" instead of {"ui", "integration"}.
      3. Final Answer:

        Groups should be passed as an array, not a single string -> Option A
      4. Quick Check:

        Groups need array syntax [OK]
      Hint: Use curly braces for multiple groups [OK]
      Common Mistakes:
      • Passing groups as one string with commas
      • Forgetting curly braces for arrays
      • Misunderstanding annotation syntax
      5. You have three test methods:
      @Test(groups = {"sanity"})
      public void testLogin() {}
      
      @Test(groups = {"regression", "sanity"})
      public void testCheckout() {}
      
      @Test(groups = {"regression"})
      public void testSearch() {}
      How would you run only the tests that belong exclusively to the "sanity" group, excluding those that also belong to "regression"?
      hard
      A. Run tests with groups "sanity" and "regression" together
      B. Run all tests with group "sanity" only
      C. Run tests with group "regression" only
      D. Run tests with group "sanity" and exclude group "regression" in the TestNG XML

      Solution

      1. Step 1: Identify tests with only "sanity" group

        testLogin belongs only to "sanity"; testCheckout belongs to both "regression" and "sanity"; testSearch belongs only to "regression".
      2. Step 2: Determine how to run only exclusive "sanity" tests

        Use TestNG XML to include "sanity" group and exclude "regression" group to run only testLogin.
      3. Final Answer:

        Run tests with group "sanity" and exclude group "regression" in the TestNG XML -> Option D
      4. Quick Check:

        Include "sanity" exclude "regression" = exclusive tests [OK]
      Hint: Include one group, exclude others in XML to filter tests [OK]
      Common Mistakes:
      • Running all tests with "sanity" ignoring exclusions
      • Running "regression" group instead
      • Running both groups together without filtering
      Recommended

      Ready to prove it?

      Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

      10 questions~5 mineasy hard