0% found this document useful (0 votes)
175 views5 pages

TestNG Interview Questions

TestNG is an open source automated testing framework that allows for flexible unit testing and supports features like grouping tests, data-driven testing, parallel test execution, and more. It offers several advantages over JUnit like easier annotations, support for additional setup/teardown methods, ability to run tests in parallel, and determining test dependencies. Key TestNG annotations include @BeforeSuite, @AfterSuite, @BeforeTest, @AfterTest, and others. The testng.xml file is used to configure test runs by setting dependencies, groups, priorities, and more.

Uploaded by

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

TestNG Interview Questions

TestNG is an open source automated testing framework that allows for flexible unit testing and supports features like grouping tests, data-driven testing, parallel test execution, and more. It offers several advantages over JUnit like easier annotations, support for additional setup/teardown methods, ability to run tests in parallel, and determining test dependencies. Key TestNG annotations include @BeforeSuite, @AfterSuite, @BeforeTest, @AfterTest, and others. The testng.xml file is used to configure test runs by setting dependencies, groups, priorities, and more.

Uploaded by

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

TestNG Interview Questions

TestNG Interview Question

Q) What is TestNG? (symphony telca)


Ans:- TestNG is an automated open source testing framework.

Q) Why you have used TestNG in your framework? Can you compare
JUNIT with TestNG framework? (Wipro,Cybage, Avaya, Teito)
Ans:-
Compare to JUnit annotations, TestNG are easy to understand
Unlike JUnit, TestNG does not require to declare @BeforeClass and
@AfterClass
Method name constraint is not there in TestNG
TestNG allows you the grouping of test cases easily which is not
possible in JUnit
TestNG supports following three additional setup: @Before/AfterSuite,
@Before/AfterTest and @Before/AfterGroup
TestNG does not need to extend any class
In TestNG, it is possible to run selenium test cases in parallel
Based on group TestNG allows you to execute the test cases
TestNG allows you to determine the dependent test cases; each test
case is autonomous to other test case

Q) What are different annotation present in TestNG? Can you name


few amongst them ?(KPIT, Techm, Citi bank, TCS)
Ans:-
@BeforeSuite
@AfterSuite
@BeforeTest
@AfterTest
@BeforeGroups
@AfterGroups
@BeforeClass

1 Shammi Jha | 8305429370


TestNG Interview Questions

@AfterClass
@BeforeMethod
@AfterMethod

Q) What is priority feature in TestNG? In addition, how we can use


this? (Synechron,Kpit, capgemeni, fluent India)
Ans:- If you want the @Test methods to be executed in your order,
then you need to use the ‘priority‘ .
Like First we need to execute a test case "Registration" before login. In
order to achive, we use need to add annotation as @Test(priority=??).
Sequence of execution is in ascending order of value. “0”is having
highest priority so it will be executed first. There is no need for your
values to be consecutive
Example:- @Test (priority=0)
Q) What is dependsOnMethods(Zensar, Wipro )
Ans:-
In real time, you will come across many situations where you have to
create test cases which are dependent on the previous test case.
Take an example I have 3 test cases.
First one which verify login credential and start application, second test
case check some validation or do some activity, third test case simply
just for log-out activity.
If my first test case does not work (failed) then it does not make any
sense to run second and third test case. So in these types of scenarios
you can use dependency between test cases.
Syntax- @Test( dependsOnMethods = {"loginTestCase"} )

2 Shammi Jha | 8305429370


TestNG Interview Questions

Q) What is testng.xml file in TestNG? (media ocean, HSBC, NTT data)


Ans:-
In any project, you will end up to a place where you need to execute so
many test cases on a run. Running a set of test cases together is call
executing a Test Suite.
Those test cases can be dependent to each other or may have to be
executed in a certain order. testng.xml file where you will configure
your test run, set test dependency, include or exclude any test,
method, class or package and set priority etc.

Q) How to group test cases in TestNG?


Ans:-
In TestNg you can form a group of test cases and run it .It allows us to
execute only set of groups while excluding another set.
Groups are specified in testng.xml file and can be used with tag.
Example:-
public class groupExamples {
@Test(groups="Regression")
public void testCaseOne()
{
System.out.println("Im in testCaseOne - And in Regression
Group");
}
@Test(groups="Regression")
public void testCaseTwo(){
System.out.println("Im in testCaseTwo - And in Regression
Group");
}
@Test(groups="Smoke Test")
public void testCaseThree(){
System.out.println("Im in testCaseThree - And in Smoke Test
Group");

3 Shammi Jha | 8305429370


TestNG Interview Questions

}
@Test(groups="Regression")
public void testCaseFour(){
System.out.println("Im in testCaseFour - And in Regression
Group");
}
}

The below is the XML file to execute, the test methods with group.
We will execute the group “Regression” which will execute the test
methods which are defined with group as “Regression”

<?xml version="1.0" encoding="UTF-8"?>


<suite name="Sample Suite">
<test name="testing">
<groups>
<run>
<include name="Regression"/>
</run>
</groups>
<classes>
<class name="com.example.group.groupExamples" />
</classes>
</test>
</suite>

Q) How to execute multiple test cases in Selenium?


(Amdocs ,Accenture)
Ans:- using TestNG.xml

Q) How to execute parallel test cases in Selenium? (PTC, mindtree)


Ans:- There are two ways

4 Shammi Jha | 8305429370


TestNG Interview Questions

1> using DataProvideranotation :- @DataProvider(parallel=true)


2> using testng.xml :- <suite name="My suite" parallel="methods" >
Q) What is Data provider in TestNG?
Ans:- It is used to parameterize the test. we can also achive parallel
execution using same.

Q) How to skip or disable particular test case? (Infy, persistent,


Avaya, Wipro)
Ans:- Two ways to do it.
1>@Test(enabled=false)
2>Write “throw new SkipException("any message");” inside a Test
method which you want to skip.

Q) How to execute only failed test cases in Selenium? (Synerzip, HCL,


Accenture, Capgemeni)
Ans:-
Every time tests fail in a suite, TestNG creates a file called testng-
failed.xml in the output directory.
This XML file contains the necessary information to rerun only these
methods that failed, utlizing this we can easily rerun the failed tests
without having to run the entire test suite.

5 Shammi Jha | 8305429370

You might also like