0% found this document useful (0 votes)
9 views7 pages

automation testing interview question

The document contains a list of 50 interview questions related to TestNG, a testing framework for Java commonly used with Selenium for automation testing. It covers various aspects of TestNG, including its features, annotations, XML configuration, and integration with tools like Jenkins. Key topics include test execution, dependency management, reporting, and handling test cases.

Uploaded by

ishivamkunal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views7 pages

automation testing interview question

The document contains a list of 50 interview questions related to TestNG, a testing framework for Java commonly used with Selenium for automation testing. It covers various aspects of TestNG, including its features, annotations, XML configuration, and integration with tools like Jenkins. Key topics include test execution, dependency management, reporting, and handling test cases.

Uploaded by

ishivamkunal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

50 Automation Testing (Core

Java with Selenium)


Interview Questions TestNG
Related

+91 80099 00785 [email protected] www.grotechminds.com


1. What is TestNG in Selenium?
TestNG (Test Next Generation) is a testing framework for Java that provides
advanced features such as annotations, parallel execution, grouping, and reporting.
It is widely used with Selenium for automated testing.
2. How is TestNG different from JUnit?
TestNG offers additional features like parallel execution, dependency testing,
grouping, and more flexible annotations compared to JUnit.
3. What are the advantages of using TestNG?
Supports parallel execution
Generates detailed HTML reports
Allows test case dependency management
Provides data-driven testing using @DataProvider
Supports test case grouping
4. How do you install TestNG in a Selenium project?
You can install TestNG via Maven (testng dependency) or manually by adding the
TestNG JAR file to your project.
5. What is the default behavior of TestNG if a test method fails?
By default, TestNG marks the test as failed and proceeds with the next test case
unless specified otherwise.
6. What is the purpose of the @Test annotation in TestNG?
The @Test annotation marks a method as a test method to be executed by TestNG.
7. What is the use of @BeforeSuite annotation in TestNG?
@BeforeSuite runs once before any tests in the suite are executed.
8. What is the difference between @BeforeTest and @BeforeMethod?
@BeforeTest: Runs once before any test cases in a <test> tag in the XML file.
@BeforeMethod: Runs before each @Test method execution.
9. How does @AfterMethod annotation work in TestNG?
@AfterMethod executes after each test method runs, useful for cleanup activities.

+91 80099 00785 [email protected] www.grotechminds.com


10. What is the use of @BeforeClass in TestNG?
@BeforeClass executes once before any test methods in a class.
11. What happens if a test method is not annotated with @Test?
TestNG will not consider the method as a test case, and it will not be executed.
12. What is the use of @AfterSuite annotation?
@AfterSuite runs once after all tests in the suite have been executed.
13. What is a TestNG XML file?
It is a configuration file (testng.xml) used to define test execution, group tests, and
specify parallel execution.
14. How can you exclude a test case using the TestNG XML file?
Using the <exclude name="testMethodName"/> tag under <methods> inside <class>.
15. What is the purpose of the <suite> tag in a TestNG XML file?
It defines a test suite and groups multiple tests together.
16. Can we run multiple test classes using TestNG XML?
Yes, by specifying multiple <class> tags inside the <test> tag.
17. How can you specify priority in TestNG XML?
You cannot directly specify priority in XML; it must be set using the priority
attribute in the @Test annotation.
18. What happens if you do not define the priority of test methods?
TestNG executes the methods in alphabetical order by default.
19. How do you define test dependencies in TestNG XML?
Using the dependsOnMethods or dependsOnGroups attribute in the @Test
annotation.
20. How does TestNG support parallel execution?
By configuring parallel execution in the testng.xml file using the parallel attribute
(methods, classes, or tests).

+91 80099 00785 [email protected] www.grotechminds.com


21. What is the use of the alwaysRun attribute in TestNG?
It ensures that a method runs even if its dependent methods fail.
22. What happens if a dependent test fails in TestNG?
The dependent test method will be skipped.
23. What is the timeout attribute in the @Test annotation?
It sets a maximum time for a test to execute. If it exceeds the limit, the test fails.
24. What is invocationCount in TestNG?
It allows a test method to be executed multiple times.
25. How do you disable a test case in TestNG?
By setting enabled=false in the @Test annotation.
26. What is the use of groups in TestNG?
Groups allow categorizing test methods and running specific groups of tests.
27. How can you run only a specific group of test cases in TestNG?
By specifying the groups attribute in the @Test annotation and running it using
include in the testng.xml file.
28. What happens when a test fails but retryAnalyzer is implemented?
The test automatically retries execution based on the retry logic defined in
retryAnalyzer.
29. How do you execute failed test cases in TestNG?
Using the testng-failed.xml file generated after execution or implementing retry
logic.
30. What is the use of the dependsOnMethods attribute?
It ensures a test method runs only after its dependent method has successfully
executed.
31. What are TestNG listeners?
They are interfaces used to modify test behavior, capture logs, and generate custom
reports.

+91 80099 00785 [email protected] www.grotechminds.com


32. What is the use of ITestListener in TestNG?
It listens to test execution events like test start, success, failure, and skipping.
33. How do you implement a TestNG listener?
By implementing the ITestListener interface and overriding its methods.
34. What is the purpose of IReporter in TestNG?
It generates custom reports after test execution.
35. What is the difference between soft assertions and hard
assertions in TestNG?
Hard assertion (Assert.assertEquals()): Stops execution immediately if it fails.
Soft assertion (SoftAssert class): Collects all assertion failures and reports them
at the end
36. How can you generate an HTML report in TestNG?
TestNG automatically generates an index.html report in the test-output folder.
37. What is @DataProvider in TestNG?
It allows passing multiple sets of data to a test method.
38. Can a @DataProvider method exist in a different class?
Yes, by specifying the class name using dataProviderClass.
39. How does TestNG handle parameterization using XML?
Using the @Parameters annotation and defining parameters in the testng.xml file.
40. What is the difference between @Factory and @DataProvider?
@DataProvider: Runs the same test method multiple times with different data.
@Factory: Dynamically creates test instances at runtime.
41. Can TestNG be integrated with Jenkins?
Yes, TestNG can be executed in Jenkins using the TestNG plugin.
42. What is the significance of the test-output folder?
It contains reports and logs generated after execution.

+91 80099 00785 [email protected] www.grotechminds.com


43. Can we run TestNG without a main() method?
Yes, TestNG is executed via annotations, XML files, or the TestNG runner.
44. What is the role of listeners in TestNG reporting?
Listeners help customize logs, screenshots, and reports.
45. How do you execute multiple test suites in TestNG?
By defining multiple <suite> tags in the testng.xml file
46. What is the default priority of test methods in TestNG?
Zero (0) if not explicitly set.
47. How do you handle exceptions in TestNG?
Using the expectedExceptions attribute in @Test.
48. How can you ignore a test in TestNG?
By setting enabled=false in the @Test annotation.
49. What happens if all tests are disabled in TestNG?
TestNG runs but does not execute any tests.
50. Can you run a single test method using TestNG XML?
Yes, by specifying the method name under <methods> in testng.xml.

+91 80099 00785 [email protected] www.grotechminds.com


FOLLOW FOR MORE

+91 80099 00785 [email protected] www.grotechminds.com

You might also like