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
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
What is the default XML configuration file for TestNG? a) test.xml b) testng-config.xml c) testng.xml d) testng-setup.xml
Which annotation in JUnit is used to indicate a test method? a) @TestCase b) @RunTest c) @Test d) @TestMethod
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
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
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
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
Which IDE feature assists in setting up TestNG in Selenium? a) TestNG plugin b) JUnit runner c) Debug mode d) Selenium IDE
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
Which Maven lifecycle phase is used to execute JUnit or TestNG tests? a) compile b) test c) package d) deploy
Test Annotations and Prioritization
Which TestNG annotation specifies the execution order of test methods? a) @ExecutionOrder b) @Priority c) @Order d) @Test(priority)
In JUnit, how do you disable a test method? a) @DisableTest b) @Ignore c) @Exclude d) @Disable
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
Which TestNG annotation executes after all test methods in a class? a) @AfterSuite b) @AfterClass c) @AfterTest d) @AfterMethod
What is the default priority value for a TestNG test method? a) 0 b) 1 c) 5 d) -1
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
Which annotation in TestNG allows skipping a test conditionally? a) @SkipTest b) @ConditionalIgnore c) @Test(enabled = false) d) @Ignore
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
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
In JUnit 5, which annotation is used to group related tests? a) @Tag b) @Group c) @Suite d) @Class
Running and Grouping Test Cases
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
Which TestNG annotation helps in executing a group of test cases? a) @RunGroup b) @GroupExecute c) @Test(groups = “groupName”) d) @Group(priority)
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)
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
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)
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
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
How do you parameterize test cases in TestNG? a) Use @DataProvider annotation b) Use @Param annotation c) Use testng.xml d) Use @ParameterizedTest
Which feature allows conditional test execution in JUnit 5? a) @Condition b) @EnabledIf c) @ConditionalTest d) @IfTest
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