0% found this document useful (0 votes)
1 views

import java (5)

@Factory creates instances of a class for different tests, while @DataProvider supplies data sets for parameterized tests. TestNG handles exceptions with try-catch blocks or the expectedExceptions attribute, and assertions verify expected versus actual results. Common assertions include assertEquals, assertTrue, assertFalse, assertNull, and assertNotNull, and TestNG supports features like parallel execution, dependency injection, grouping, custom listeners, reporting, data-driven testing, test skipping, priority, logging, and timeout testing.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

import java (5)

@Factory creates instances of a class for different tests, while @DataProvider supplies data sets for parameterized tests. TestNG handles exceptions with try-catch blocks or the expectedExceptions attribute, and assertions verify expected versus actual results. Common assertions include assertEquals, assertTrue, assertFalse, assertNull, and assertNotNull, and TestNG supports features like parallel execution, dependency injection, grouping, custom listeners, reporting, data-driven testing, test skipping, priority, logging, and timeout testing.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

17. What is the difference between @Factory and @DataProvider annotation?

• @Factory
creates instances of a class for different tests, while @DataProvider provides data sets for
parameterized tests within a single instance. 18. How do you handle exceptions in
TestNG? • You can handle exceptions using try-catch blocks within your test methods or
by using expectedExceptions attribute in the @Test annotation. 19. What are assertions in
TestNG? • Assertions are used to verify whether the expected results match actual results
during testing, helping determine if a test has passed or failed. 20. Describe any five
common TestNG assertions. • Common assertions include: • Assert.assertEquals() •
Assert.assertTrue() • Assert.assertFalse() • Assert.assertNull() • Assert.assertNotNull()
Advanced TestNG Interview Questions 21. How do you implement parallel execution in
TestNG? xml 22. What is dependency injection in TestNG? • Dependency injection allows
you to inject dependencies into your classes automatically, making it easier to manage
object creation and lifecycle. 23. How do you create groups in TestNG? java @Test(groups
= {"smoke"}) public void smokeTest() { } @Test(groups = {"regression"}) public void
regressionTest() { } 24. Explain how to create custom listeners in TestNG. • Implement
interfaces like ITestListener or IReporter and override their methods to define custom
behavior during test execution. 25. What are some common listeners provided by TestNG?
• Common listeners include: • ITestListener • IReporter • IInvocationListener 26. How do
you generate reports using TestNG? • You can generate HTML reports automatically after
running tests, or you can implement custom reporting using listeners. 27. Explain how
data-driven testing works with DataProvider in TestNG. java @DataProvider(name = "data-
provider") public Object[][] dataProviderMethod() { return new Object[][] { {"data1"},
{"data2"} }; } @Test(dataProvider = "data-provider") public void dataDrivenTest(String data)
{ } 28. How do you skip tests based on certain conditions? java if (condition) { throw new
SkipException("Skipping this test"); } 29. What is the use of priority in TestNG? • Priority
determines the order of execution for test methods; lower numbers have higher priority.
30. Explain how to implement logging in your TestNG tests. java Logger logger =
Logger.getLogger(YourClassName.class); logger.info("This is an info message."); 31. How
do you perform timeout testing in TestNG? java @Test(timeOut = 1000) public void
longRunningTest() { // This will fail if it takes longer than 1 second.

You might also like