Following are frequently asked questions in interviews for freshers as well as experienced TestNG professionals.
1) What is TestNG?
TestNG is an automated open source testing framework. It is based on JUnit framework but is not a JUnit extension.
2) What are the TestNG features?
TestNG features include
3) List out the advantages of TestNG over Junit?
Advantages of TestNG over JUnit includes
4) What are the basic steps required in writing TestNG tests?
The basic steps required in writing TestNG includes
5) List out various ways in which TestNG can be invoked.
TestNG can be invoked in different ways like
6) Explain the use of testng.xml file
File testing.xml captures your entire testing in XML. This file makes it easy to define all your test suite and their parameters in one file, which you can verify in your code repository or e-mail to co-workers. It also makes it easy to pull out subsets of your tests or split several runtime configurations.
7) In TestNG how can you disable a test?
To disable the test case you don’t want, you can use annotations @Test(enabled = false).
8) What is Time-Out test in TestNG?
The Time-Out test in TestNG is nothing but the time allotted to perform unit testing. If the unit test fails to finish in that specific time limit, TestNG will abandon further software testing and mark it as a failure.
9) Explain exception test
TestNG gives the option for tracing the Exception handling of code. You can test whether a code throws the expected results or not. The expected Exceptions parameter is availed along with @Test annotation.
10) What does the “suite test” does in TestNG?
“Suite Test” is done when you have to run a few unit tests together, “ Suite Test” bundle this unit test together. An XML file is used to run the suite test.
11) What is Parameterized Testing?
Parameterized testing allows developers to execute the same test over and over again using different values. In two different ways TestNG allows you to pass parameters directly to your test methods.
12) How you can run the JUnit tests using TestNG?
You can run the JUnit tests using TestNG by
This approach also enables you to convert your existing JUnit test to TestNG.
13) What does @Test(invocationCount=?) and (threadPoolSize=?) indicates?
14) What are the different ways in which you can produce reports for TestNG results?
There are two ways to produce a report with Test NG, they are
15) What is Group Test in TestNG?
It is a new feature included in TestNG; it allows you to dispatch methods into proper portions and perform grouping of test methods. With group test, you can not only declare methods that belong to groups, but you can also specify test groups that contain other groups. Groups are determined in your testing.xml file using the group test.
16) What are the ways to allow TestNG allows you to specify dependencies?
TestNG allows you to specify dependencies in two ways
17) What does it mean when you have to pass parameters using data-providers in TestNG?
When you have to pass complex parameter or parameters that are to be created from Java, in such instance parameters can be passed using Data providers. The annotation for data provider is @DataProvider. This annotation has only a single string attribute if the name is not declared; the Data provider’s name automatically defaults to the method’s name. A data provider yields back an array of objects.
18) Name various methods to execute tests in TestNG?
The tests in TestNG are executed using TestNG class. For running tests in TestNG testing framework, the class is the main entry point. Users can make their TestNG object and invoke it in many different ways like
19) Give sample TestNG code
package firsttestngpackage; import org.openqa.selenium.*; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.Assert; import org.testng.annotations.*; public class firsttestngfile { public String baseUrl = "http://demo.guru99.com/test/newtours/"; String driverPath = "C:\\geckodriver.exe"; public WebDriver driver ; @Test public void verifyHomepageTitle() { System.out.println("launching firefox browser"); System.setProperty("webdriver.firefox.marionette", driverPath); driver = new FirefoxDriver(); driver.get(baseUrl); String expectedTitle = "Welcome: Mercury Tours"; String actualTitle = driver.getTitle(); Assert.assertEquals(actualTitle, expectedTitle); driver.close(); } }
View Comments
Good One for Preparing for Interviews
In question no 6, you have written testing.xml instead of testng.xml
Thanks ... this is corrected
First line of 3rd question should be "Advantages of TestNG over JUnit includes".
Thanks for the questions.
Error Fixed!
11) What is parametric testing? It should be What is Parameterized testing ?
Hi, thanks for writing. It is reviewed and updated.