What is the purpose of the <suite> tag in a testng.xml file?
The <suite> tag defines the entire test suite. It groups multiple <test> tags and controls the overall execution of tests in TestNG.
Click to reveal answer
beginner
How do you specify which test classes to run inside a <test> tag in testng.xml?
Inside the <test> tag, use the <classes> tag, and inside it, add one or more <class name="fully.qualified.ClassName"/> tags.
Click to reveal answer
intermediate
What attribute in the <suite> tag controls the parallel execution of tests?
The 'parallel' attribute controls parallel execution. It can be set to 'tests', 'classes', 'methods', or 'instances' to run those elements in parallel.
Click to reveal answer
intermediate
How can you set a timeout for all tests in a test suite using testng.xml?
You can set the 'time-out' attribute inside the <test> tag or use listeners in code. The 'time-out' attribute specifies the max time in milliseconds a test can run.
Click to reveal answer
beginner
Explain the role of the <parameter> tag in testng.xml.
The <parameter> tag allows you to pass values to test methods. You define a name and value in testng.xml, and the test method can receive it using @Parameters annotation.
Click to reveal answer
Which tag in testng.xml defines a group of tests to run together?
A<test>
B<suite>
C<class>
D<methods>
✗ Incorrect
The tag groups multiple tags and defines the whole test suite.
How do you specify a test class to run in testng.xml?
A<class name="fully.qualified.ClassName"/>
B<class>fully.qualified.ClassName</class>
C<testcase>
D<class name="ClassName"/>
✗ Incorrect
Inside , you specify to run that class.
What does setting parallel="methods" in <suite> do?
ARuns all test classes sequentially
BRuns all tests in parallel
CRuns all test methods in parallel
DRuns all test suites in parallel
✗ Incorrect
parallel="methods" runs all test methods in parallel threads.
Where do you define parameters to pass to test methods in testng.xml?
AInside <suite> or <test> using <parameter>
BInside <class> tag
CInside <methods> tag
DInside <test> using <parameter-set>
✗ Incorrect
Parameters are defined inside or tags using .
What is the default execution order of tests in testng.xml if parallel is not set?
AParallel execution of tests
BRandom execution order
CDepends on JVM
DSequential execution of tests
✗ Incorrect
By default, tests run sequentially if parallel attribute is not set.
Describe the structure of a basic testng.xml file and explain the role of each main tag.
Think about how you organize tests in groups and classes.
You got /4 concepts.
How can you configure parallel execution and parameter passing in testng.xml? Give examples.
Consider how to speed up tests and customize test inputs.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of the testng.xml file in Selenium testing?
easy
A. To write the Selenium WebDriver code
B. To store test data like usernames and passwords
C. To group and organize test classes and methods to run together
D. To generate HTML reports after test execution
Solution
Step 1: Understand the role of testng.xml
The testng.xml file is used to define which tests to run and how to organize them.
Step 2: Identify the main purpose
It groups test classes and methods so they can be run together as a suite.
Final Answer:
To group and organize test classes and methods to run together -> Option C
Quick Check:
Test suite grouping = To group and organize test classes and methods to run together [OK]
Hint: Remember: testng.xml organizes tests to run as a group [OK]
Common Mistakes:
Confusing testng.xml with test code files
Thinking testng.xml stores test data
Assuming testng.xml generates reports
2. Which of the following is the correct way to define a test suite in testng.xml?
easy
A.
B.
C.
D.
Solution
Step 1: Recall the correct XML structure for TestNG suites
The root element is <suite>, inside it we define <test>, then <classes> and <class>.
Step 2: Match the options with correct structure
correctly follows this order and syntax.
Final Answer:
<suite name="MySuite"><test name="Test1"><classes><class name="TestClass"/></classes></test></suite> -> Option A
Quick Check:
Suite > Test > Classes > Class = [OK]
Hint: Remember XML order: suite > test > classes > class [OK]
Common Mistakes:
Swapping <suite> and <test> tags
Placing <class> directly under <suite>
Using wrong tag names or attributes
3. Given the following testng.xml snippet, what tests will run?
B. The <test> tag is missing the parallel attribute
C. The class name must include the package name
D. The <class> tag should be self-closing or empty, not with separate open and close tags
Solution
Step 1: Check the <class> tag syntax
In TestNG XML, <class> should be self-closing like <class name="TestClass"/> or empty without content.
Step 2: Identify the error in the given XML
The given XML uses separate open and close tags for <class> which is invalid and causes tests not to run.
Final Answer:
The <class> tag should be self-closing or empty, not with separate open and close tags -> Option D
Quick Check:
Use self-closing <class> tag = The <class> tag should be self-closing or empty, not with separate open and close tags [OK]
Hint: Use self-closing tag in testng.xml [OK]
Common Mistakes:
Adding parallel attribute thinking it fixes syntax
Forgetting package name but that doesn't stop tests
Assuming thread-count is mandatory
5. You want to run two test classes LoginTest and PaymentTest in parallel but limit total threads to 1 in testng.xml. Which configuration achieves this?
hard
A.
B.
C.
D.
Solution
Step 1: Understand parallel and thread-count attributes
Setting parallel="classes" runs test classes in parallel, and thread-count="1" limits to one thread, so classes run one at a time.
Step 2: Check options for matching configuration
sets parallel to classes and thread-count to 1, matching the requirement.
Final Answer:
Option A configuration runs classes in parallel but limits threads to 1 -> Option A
Quick Check:
parallel="classes" + thread-count=1 =
[OK]
Hint: parallel="classes" with thread-count=1 runs classes sequentially [OK]
Common Mistakes:
Using parallel="tests" with thread-count > 1 runs multiple threads