MCQs on Introduction to TestNG/JUnit | Selenium

Boost your Selenium testing expertise with TestNG/JUnit MCQs. Learn about framework setup, master test annotations and prioritization, and explore running and grouping test cases for robust automation.


MCQs on Introduction to TestNG/JUnit in Selenium

Setting up TestNG or JUnit Framework

  1. Which dependency is added to a Maven project to use TestNG?
    a) org.testng:testng
    b) org.seleniumhq.selenium:testng
    c) org.junit:junit
    d) org.testng:selenium
  2. What is the default XML configuration file for TestNG?
    a) test.xml
    b) testng-config.xml
    c) testng.xml
    d) testng-setup.xml
  3. Which annotation in JUnit is used to indicate a test method?
    a) @TestCase
    b) @RunTest
    c) @Test
    d) @TestMethod
  4. How do you configure a JUnit test class to run with a specific test runner?
    a) Use @RunWith annotation
    b) Use @Runner annotation
    c) Use @Test annotation
    d) Use @ExecuteWith annotation
  5. What is the purpose of the TestNG Suite tag in the XML file?
    a) To configure multiple test classes
    b) To execute a single test class
    c) To specify the framework version
    d) To define data providers
  6. How do you integrate JUnit with Selenium WebDriver?
    a) Use WebDriver APIs in JUnit test methods
    b) Import selenium.junit package
    c) Use TestNG as a wrapper
    d) Add JUnit dependency to WebDriver
  7. What is the key benefit of TestNG over JUnit 4?
    a) No XML configuration required
    b) Parallel test execution support
    c) No annotations needed
    d) Integrated WebDriver support
  8. Which IDE feature assists in setting up TestNG in Selenium?
    a) TestNG plugin
    b) JUnit runner
    c) Debug mode
    d) Selenium IDE
  9. How do you execute TestNG tests via the command line?
    a) Use mvn test
    b) Use testng.xml with java command
    c) Use run-testng command
    d) Use selenium-runner
  10. Which Maven lifecycle phase is used to execute JUnit or TestNG tests?
    a) compile
    b) test
    c) package
    d) deploy

Test Annotations and Prioritization

  1. Which TestNG annotation specifies the execution order of test methods?
    a) @ExecutionOrder
    b) @Priority
    c) @Order
    d) @Test(priority)
  2. In JUnit, how do you disable a test method?
    a) @DisableTest
    b) @Ignore
    c) @Exclude
    d) @Disable
  3. What does the @BeforeTest annotation do in TestNG?
    a) Runs once before all tests in a suite
    b) Runs before each test method
    c) Runs before all test classes in a package
    d) Runs before any method annotated with @Test
  4. Which TestNG annotation executes after all test methods in a class?
    a) @AfterSuite
    b) @AfterClass
    c) @AfterTest
    d) @AfterMethod
  5. What is the default priority value for a TestNG test method?
    a) 0
    b) 1
    c) 5
    d) -1
  6. How do you run a JUnit test in a specific order?
    a) Use @Test(priority)
    b) Use @Order annotation
    c) Use @FixMethodOrder
    d) Use @RunWith
  7. Which annotation in TestNG allows skipping a test conditionally?
    a) @SkipTest
    b) @ConditionalIgnore
    c) @Test(enabled = false)
    d) @Ignore
  8. How can you specify dependency between test methods in TestNG?
    a) Use dependsOnMethods attribute in @Test
    b) Use @Dependency annotation
    c) Use priority levels
    d) Use dependsOnClasses attribute
  9. What happens when two test methods in TestNG have the same priority?
    a) The first declared test runs first
    b) Random execution
    c) Alphabetical order execution
    d) Execution fails
  10. In JUnit 5, which annotation is used to group related tests?
    a) @Tag
    b) @Group
    c) @Suite
    d) @Class

Running and Grouping Test Cases

  1. How can you group tests in TestNG?
    a) Use groups attribute in @Test
    b) Use testng.xml file
    c) Use @Group annotation
    d) Both a and b
  2. Which TestNG annotation helps in executing a group of test cases?
    a) @RunGroup
    b) @GroupExecute
    c) @Test(groups = “groupName”)
    d) @Group(priority)
  3. How can you exclude test methods from a TestNG suite?
    a) Use exclude tag in testng.xml
    b) Use @Exclude annotation
    c) Use skip attribute in @Test
    d) Use @Test(enabled = false)
  4. Which method executes TestNG tests in parallel?
    a) Parallel execution is not supported in TestNG
    b) Specify parallel attribute in testng.xml
    c) Use @Parallel annotation
    d) Use @AsyncTest
  5. What parameter controls the thread count for parallel execution in TestNG?
    a) thread-count in testng.xml
    b) @ThreadCount annotation
    c) parallel.threads in Java code
    d) @Parallel(threadCount)
  6. How can you run JUnit tests from multiple classes together?
    a) Use @Suite annotation
    b) Use @RunGroup annotation
    c) Use @TestPackage annotation
    d) Use testng.xml
  7. What is the default behavior when TestNG encounters a failed test?
    a) Execution stops immediately
    b) Retry the test once
    c) Continue execution and log the failure
    d) Ignore the failure
  8. How do you parameterize test cases in TestNG?
    a) Use @DataProvider annotation
    b) Use @Param annotation
    c) Use testng.xml
    d) Use @ParameterizedTest
  9. Which feature allows conditional test execution in JUnit 5?
    a) @Condition
    b) @EnabledIf
    c) @ConditionalTest
    d) @IfTest
  10. How do you run only a specific set of test cases in TestNG?
    a) Use include tag in testng.xml
    b) Use group filters in testng.xml
    c) Use @Group annotation
    d) Both a and b

Answer Key

QnoAnswer (Option with Text)
1a) org.testng:testng
2c) testng.xml
3c) @Test
4a) Use @RunWith annotation
5a) To configure multiple test classes
6a) Use WebDriver APIs in JUnit test methods
7b) Parallel test execution support
8a) TestNG plugin
9b) Use testng.xml with java command
10b) test
11d) @Test(priority)
12b) @Ignore
13a) Runs once before all tests in a suite
14b) @AfterClass
15a) 0
16c) Use @FixMethodOrder
17c) @Test(enabled = false)
18a) Use dependsOnMethods attribute in @Test
19a) The first declared test runs first
20a) @Tag
21d) Both a and b
22c) @Test(groups = “groupName”)
23a) Use exclude tag in testng.xml
24b) Specify parallel attribute in testng.xml
25a) thread-count in testng.xml
26a) Use @Suite annotation
27c) Continue execution and log the failure
28a) Use @DataProvider annotation
29b) @EnabledIf
30d) Both a and b

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top