SlideShare a Scribd company logo
Top 20 TestNG Interview Questions
for SDET
By DevLabs Alliance
Visit us at:
www.devlabsalliance.com
Email:
training@devlabsalliance.com
Contact: +91 9717514555
TestNG Interview Questions for SDET
1. What is TestNG?
TestNG is a testing framework used for executing the unit tests in Java.
TestNG is an automated open source testing framework that can be integrated with
Selenium and capable of making Selenium tests easier to understand and provide multiple
capabilities like assertion, report generation, parallel test execution, etc.
It is inspired by JUnit. It has all the features of JUnit and has its own new features which
makes it more powerful.
Full form of TestNG is “Testing Next Generation”.
TestNG Interview Questions for SDET
2. What are the advantages of TestNG over JUnit?
The advantages of TestNG over JUnit are:
• TestNG Annotations are easier to use and understand.
• Test Cases in TestNG can be grouped more easily.
• TestNG provides feature to create and execute parallel tests.
• TestNG is used to create detailed HTML reports.
• TestNG allows to define dependency of one test method over other method.
• TestNG allows to assign priority to test cases.
TestNG Interview Questions for SDET
3. What is the use of testng.xml file?
Testng.xml is used for configuring the whole test suite. The various uses of TestNG are as
follows:
• All the tests in the test suite are triggered by testing.xml
• It is used to pass parameters to test scripts.
• It is used to support inclusion and exclusion of tests.
• It is used to create the test groups.
• It supports the parallel execution of test cases.
TestNG Interview Questions for SDET
4. What are the different annotations available in TestNG?
The different annotations of TestNG are:
• @BeforeTest
• @AfterTest
• @BeforeClass
• @AfterClass
• @BeforeMethod
• @AfterMethod
• @BeforeSuite
• @AfterSuite
• @BeforeGroups
• @AfterGroups
• @Test
TestNG Interview Questions for SDET
5. What is the sequence of execution of annotations in TestNG?
The sequence of execution of annotations is as follows:
• @BeforeSuite
• @BeforeTest
• @BeforeClass
• @BeforeMethod
• @Test
• @AfterMethod
• @AfterClass
• @AfterTest
• @AfterSuite
TestNG Interview Questions for SDET
6. How to create a xml file in TestNG?
To create xml file in TestNG, follow the following steps:
• Right click on Java project folder.
• Go to “New” and select “File” option.
• In New file wizard, specify file name as “testing.xml”.
• Click on Finish button.
This will add testing.xml file under Java project folder.
TestNG Interview Questions for SDET
7. What is a dependency in TestNG?
Dependency is used for some of the methods on which many methods are dependent on.
For eg.: For any application, if login page do not work, then it should not test the rest of
test scenarios.
In this case we would be using the LoginTest method on which other tests are dependent.
@Test(dependsOnMethods=“LoginTest”)
Public void SearchPage()
{
}
Since SearchPage is dependent on LoginTest method, so if LoginTest method fails, then
SearchPage method will not get executed.
TestNG Interview Questions for SDET
8. What is InvocationCount in TestNG?
InvocationCount is used to execute same test case multiple times.
For eg.:
@Test(invocationCount = 10)
Public void Login()
{
}
In this case, Login() method will execute 10 times.
TestNG Interview Questions for SDET
9. What is timeOut in TestNG?
If we want to terminate any method in the test script which is taking too much time to
execute, then we can use “timeOut” attributein TestNG.
Time is provided in miliseconds(ms)
For eg.:
@Test(timeOut = 2000)
Public void Login()
{
}
In this case, the Login() method will get terminated in 2000 ms (2 seconds) and the test
case gets Failed.
TestNG Interview Questions for SDET
10. What are common assertions in TestNG?
The common TestNG assertions are:
• Assert.assertEquals(string actual, string expected) :
If both the strings are equal, then only test case will pass.
• Assert.assertTrue(condition) :
It accepts a Boolean value. The assertion will pass if condition is True, otherwise it will
get fail.
• Assert.assertFalse(condition) :
It accepts a Boolean value. The assertion will pass if condition is False, otherwise it will
get fail.
TestNG Interview Questions for SDET
11. How a test can be disabled in TestNG?
To disable any test case in TestNG, we use “enabled” attribute.
For eg.:
@Test(enabled= “false”)
Public void LoginTest()
{
}
In this case, LoginTest() method will get disabled.
TestNG Interview Questions for SDET
12. What is assertion and what are the types of asserts in TestNG?
Assertion is used to validate the results of test cases.
There are two types of assertion:
• HardAssert: HardAssert is used to validate the test result. If hard assert fails, then none
of the code execution will take place after Assert statement.
Assert.assertEquals(actual value, expected value)
• Soft Assert: Soft Assert is also used to validate the test results but if soft assert fails,
then also execution of code will be continued for next statements.
To create a soft assert, object of “softAssert” class is created:
softAssert sAssert = new softAssert();
sAssert.assertAll();
TestNG Interview Questions for SDET
13. How to set test case priority in TestNG?
Priority attribute is used to set the order of execution of test cases.
If priority is not set then the test scripts are executed in alphabetical order.
For eg.:
Public class PriorityTestCase{
@Test(priority=0)
public void testCase1(){
system.out.println(“DLA Test Case 1”);
}
@Test(priority=1)
public void testCase2(){
system.out.println(“DLA Test Case 2”);
}
}
In this case, testCase1 will be executed first and then testCase2 will get execeuted.
TestNG Interview Questions for SDET
14. How can we pass parameter to test script using TestNG?
We can pass parameter to test scripts by using @Parameter annotation in test and
“parameter” tag in testing.xml.
Sample testing.xml:
<suite name = “dlaTestSuite”>
<test name = “dlaTest”>
<parameter name = “dlaParamName” value = “dlaParamValue”>
<classes>
<class name = “dlaTestFile” />
</classes> </test> </suite>
Sample Test Script:
public class dlaTestFile{
@Test
@Parameters(“dlaParamName”)
public void dlaParameterTest(string paramValue){
System.out.println(sampleParamName);
} }
TestNG Interview Questions for SDET
15. How can we create data driven framework using TestNG?
To create data driven framework, @DataProvider is used in which data is passed to the
associated test method and multiple iteration of tests run for different data values passed
from @DataProvider method.
For eg.:
@DataProvider(name = “dlaDataProvider”)
public Object[] [] dataProviderMethod() {
return new Object[] [] {{“dev”, “lab”}, {“devlabs”, “alliance”}};
}
@Test(dataProvider = “dlaDataProvider”)
public void dlaTest(string s1, string s2) {
system.out.println(s1 + “ “ + s2);
}
TestNG Interview Questions for SDET
16. What is the use of @Listener annotation in TestNG?
TestNG provides some kinds of listeners using which some actions can be performed in
case an event has triggered. Mostly TestNG listeners are used for configuration of reports
and logging.
The most widely used lisetner in TestNG is ITestListener interface. It contains methods like
onTestSuccess, onTestFailure, onTestSkipped etc. To implement this interface, we have to
create a listener class of our own. After that @Listener annotation is used to specify that
for a particular test class our customized listener class should be used.
For eg.:
@Listeners(PackageName.CustomizedListenerClassName.class)
public class dlaTestClass {
WebDriver driver = new FirefoxDriver();
@Test
public void dlaTestMethod(){
//test logic
}}
TestNG Interview Questions for SDET
17. What is the difference between @Factory and @DataProvider
annotation?
@Factory method creates instances of test class and run all the test methods in that class
with different set of data.
@DataProvider is bound to individual test methods and run the specific methods multiple
times.
TestNG Interview Questions for SDET
18. How can we run test cases in parallel using TestNG?
To run the tests in parallel in TestNG, we have to add these two key value pairs in suite-
• Parallel = "{methods/tests/classes}“
• thread-count= "{number of thread you want to run simultaneously}“
For eg.:
<suite name = “DLATestSuite” parallel = “methods” thread-count = “5”>
TestNG Interview Questions for SDET
19. How can we make sure a test method runs even if the test methods
or groups on which it depends fail or get skipped?
To run the test method even if test methods or groups on which it depends get fail or
skipped, we use “alwaysRun” attribute of @Test annotation.
For eg.:
@Test
public void parentTest() {
Assert.Fail(“Failed Test”);
}
@Test(dependsOnMethods = {“parentTest”}, alwaysRun = true)
Public void DependentTest() {
System.out.println(“Test DLA”);
}
TestNG Interview Questions for SDET
20. How to handle exceptions in TestNG?
To handle exception in methods we can mention the exception in @Test annotation so
that the test case does not fail.
For eg.: If a test method is expected to have “numberFormatException” exception, then
the test case will fail because of this exception if no try catch block is specified.
But this can be handled in TestNG by using “expectedException” attribute:
@Test(expectedException=numberFormatException.class)
After this the test case will run without failing.
Visit us at: www.devlabsalliance.com
Email: training@devlabsalliance.com
Contact: +91 9717514555

More Related Content

What's hot

Test ng tutorial
Test ng tutorialTest ng tutorial
Test ng tutorial
Srikrishna k
 
Junit and testNG
Junit and testNGJunit and testNG
Junit and testNG
Марія Русин
 
Introduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit frameworkIntroduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit framework
BugRaptors
 
TestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit TestingTestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit Testing
Bethmi Gunasekara
 
testng
testngtestng
TestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the warTestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the war
Oleksiy Rezchykov
 
TestNG introduction
TestNG introductionTestNG introduction
TestNG introductionDenis Bazhin
 
TestNG Data Binding
TestNG Data BindingTestNG Data Binding
TestNG Data Binding
Matthias Rothe
 
Thread & concurrancy
Thread & concurrancyThread & concurrancy
Thread & concurrancy
Onkar Deshpande
 
TestNG with selenium
TestNG with seleniumTestNG with selenium
TestNG with selenium
Gousalya Ramachandran
 
Unit testing
Unit testingUnit testing
Unit testing
Murugesan Nataraj
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practicesnickokiss
 
Unit testing with Junit
Unit testing with JunitUnit testing with Junit
Unit testing with Junit
Valerio Maggio
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
Thomas Zimmermann
 
IT Talk TestNG 6 vs JUnit 4
IT Talk TestNG 6 vs JUnit 4IT Talk TestNG 6 vs JUnit 4
IT Talk TestNG 6 vs JUnit 4
Andrey Oleynik
 
Test ng
Test ngTest ng
Test ng
fbenault
 
Selenium TestNG
Selenium TestNGSelenium TestNG
Selenium TestNG
KadarkaraiSelvam
 
Testing In Java
Testing In JavaTesting In Java
Testing In Java
David Noble
 

What's hot (20)

Test ng tutorial
Test ng tutorialTest ng tutorial
Test ng tutorial
 
Junit and testNG
Junit and testNGJunit and testNG
Junit and testNG
 
Introduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit frameworkIntroduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit framework
 
TestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit TestingTestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit Testing
 
testng
testngtestng
testng
 
TestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the warTestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the war
 
TestNG introduction
TestNG introductionTestNG introduction
TestNG introduction
 
TestNG Data Binding
TestNG Data BindingTestNG Data Binding
TestNG Data Binding
 
Test ng for testers
Test ng for testersTest ng for testers
Test ng for testers
 
Thread & concurrancy
Thread & concurrancyThread & concurrancy
Thread & concurrancy
 
TestNG with selenium
TestNG with seleniumTestNG with selenium
TestNG with selenium
 
Unit testing
Unit testingUnit testing
Unit testing
 
Unit testing best practices
Unit testing best practicesUnit testing best practices
Unit testing best practices
 
Unit testing with Junit
Unit testing with JunitUnit testing with Junit
Unit testing with Junit
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
JUNit Presentation
JUNit PresentationJUNit Presentation
JUNit Presentation
 
IT Talk TestNG 6 vs JUnit 4
IT Talk TestNG 6 vs JUnit 4IT Talk TestNG 6 vs JUnit 4
IT Talk TestNG 6 vs JUnit 4
 
Test ng
Test ngTest ng
Test ng
 
Selenium TestNG
Selenium TestNGSelenium TestNG
Selenium TestNG
 
Testing In Java
Testing In JavaTesting In Java
Testing In Java
 

Similar to Dev labs alliance top 20 testng interview questions for sdet

Testing Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation FrameworksTesting Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation Frameworks
Łukasz Morawski
 
Testing with Junit4
Testing with Junit4Testing with Junit4
Testing with Junit4
Amila Paranawithana
 
Testing And Drupal
Testing And DrupalTesting And Drupal
Testing And Drupal
Peter Arato
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Avinash Kadam
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End Development
All Things Open
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
SumitKumar918321
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
Onkar Deshpande
 
Test Case Naming 02
Test Case Naming 02Test Case Naming 02
Test Case Naming 02SriluBalla
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
Attila Bertók
 
Google test training
Google test trainingGoogle test training
Google test training
Thierry Gayet
 
S313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discoveringS313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discovering
romanovfedor
 
Break through e2e-testing
Break through e2e-testingBreak through e2e-testing
Break through e2e-testingtameemahmed5
 
Test Driven Development with Sql Server
Test Driven Development with Sql ServerTest Driven Development with Sql Server
Test Driven Development with Sql Server
David P. Moore
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
Devvrat Shukla
 
Unit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile AppsUnit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile Apps
Marcelo Busico
 
Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2Tricode (part of Dept)
 
An introduction to unit testing
An introduction to unit testingAn introduction to unit testing
An introduction to unit testing
Adam Stephensen
 
SELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdfSELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdf
Eric Selje
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier
Christian Hujer
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
Ahmed M. Gomaa
 

Similar to Dev labs alliance top 20 testng interview questions for sdet (20)

Testing Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation FrameworksTesting Experience - Evolution of Test Automation Frameworks
Testing Experience - Evolution of Test Automation Frameworks
 
Testing with Junit4
Testing with Junit4Testing with Junit4
Testing with Junit4
 
Testing And Drupal
Testing And DrupalTesting And Drupal
Testing And Drupal
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
We Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End Development
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
 
Test Case Naming 02
Test Case Naming 02Test Case Naming 02
Test Case Naming 02
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
Google test training
Google test trainingGoogle test training
Google test training
 
S313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discoveringS313352 optimizing java device testing with automatic feature discovering
S313352 optimizing java device testing with automatic feature discovering
 
Break through e2e-testing
Break through e2e-testingBreak through e2e-testing
Break through e2e-testing
 
Test Driven Development with Sql Server
Test Driven Development with Sql ServerTest Driven Development with Sql Server
Test Driven Development with Sql Server
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
 
Unit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile AppsUnit Testing & TDD Training for Mobile Apps
Unit Testing & TDD Training for Mobile Apps
 
Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2
 
An introduction to unit testing
An introduction to unit testingAn introduction to unit testing
An introduction to unit testing
 
SELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdfSELJE_Database_Unit_Testing_Slides.pdf
SELJE_Database_Unit_Testing_Slides.pdf
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 

Recently uploaded

Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 

Recently uploaded (20)

Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 

Dev labs alliance top 20 testng interview questions for sdet

  • 1. Top 20 TestNG Interview Questions for SDET By DevLabs Alliance Visit us at: www.devlabsalliance.com Email: training@devlabsalliance.com Contact: +91 9717514555
  • 2. TestNG Interview Questions for SDET 1. What is TestNG? TestNG is a testing framework used for executing the unit tests in Java. TestNG is an automated open source testing framework that can be integrated with Selenium and capable of making Selenium tests easier to understand and provide multiple capabilities like assertion, report generation, parallel test execution, etc. It is inspired by JUnit. It has all the features of JUnit and has its own new features which makes it more powerful. Full form of TestNG is “Testing Next Generation”.
  • 3. TestNG Interview Questions for SDET 2. What are the advantages of TestNG over JUnit? The advantages of TestNG over JUnit are: • TestNG Annotations are easier to use and understand. • Test Cases in TestNG can be grouped more easily. • TestNG provides feature to create and execute parallel tests. • TestNG is used to create detailed HTML reports. • TestNG allows to define dependency of one test method over other method. • TestNG allows to assign priority to test cases.
  • 4. TestNG Interview Questions for SDET 3. What is the use of testng.xml file? Testng.xml is used for configuring the whole test suite. The various uses of TestNG are as follows: • All the tests in the test suite are triggered by testing.xml • It is used to pass parameters to test scripts. • It is used to support inclusion and exclusion of tests. • It is used to create the test groups. • It supports the parallel execution of test cases.
  • 5. TestNG Interview Questions for SDET 4. What are the different annotations available in TestNG? The different annotations of TestNG are: • @BeforeTest • @AfterTest • @BeforeClass • @AfterClass • @BeforeMethod • @AfterMethod • @BeforeSuite • @AfterSuite • @BeforeGroups • @AfterGroups • @Test
  • 6. TestNG Interview Questions for SDET 5. What is the sequence of execution of annotations in TestNG? The sequence of execution of annotations is as follows: • @BeforeSuite • @BeforeTest • @BeforeClass • @BeforeMethod • @Test • @AfterMethod • @AfterClass • @AfterTest • @AfterSuite
  • 7. TestNG Interview Questions for SDET 6. How to create a xml file in TestNG? To create xml file in TestNG, follow the following steps: • Right click on Java project folder. • Go to “New” and select “File” option. • In New file wizard, specify file name as “testing.xml”. • Click on Finish button. This will add testing.xml file under Java project folder.
  • 8. TestNG Interview Questions for SDET 7. What is a dependency in TestNG? Dependency is used for some of the methods on which many methods are dependent on. For eg.: For any application, if login page do not work, then it should not test the rest of test scenarios. In this case we would be using the LoginTest method on which other tests are dependent. @Test(dependsOnMethods=“LoginTest”) Public void SearchPage() { } Since SearchPage is dependent on LoginTest method, so if LoginTest method fails, then SearchPage method will not get executed.
  • 9. TestNG Interview Questions for SDET 8. What is InvocationCount in TestNG? InvocationCount is used to execute same test case multiple times. For eg.: @Test(invocationCount = 10) Public void Login() { } In this case, Login() method will execute 10 times.
  • 10. TestNG Interview Questions for SDET 9. What is timeOut in TestNG? If we want to terminate any method in the test script which is taking too much time to execute, then we can use “timeOut” attributein TestNG. Time is provided in miliseconds(ms) For eg.: @Test(timeOut = 2000) Public void Login() { } In this case, the Login() method will get terminated in 2000 ms (2 seconds) and the test case gets Failed.
  • 11. TestNG Interview Questions for SDET 10. What are common assertions in TestNG? The common TestNG assertions are: • Assert.assertEquals(string actual, string expected) : If both the strings are equal, then only test case will pass. • Assert.assertTrue(condition) : It accepts a Boolean value. The assertion will pass if condition is True, otherwise it will get fail. • Assert.assertFalse(condition) : It accepts a Boolean value. The assertion will pass if condition is False, otherwise it will get fail.
  • 12. TestNG Interview Questions for SDET 11. How a test can be disabled in TestNG? To disable any test case in TestNG, we use “enabled” attribute. For eg.: @Test(enabled= “false”) Public void LoginTest() { } In this case, LoginTest() method will get disabled.
  • 13. TestNG Interview Questions for SDET 12. What is assertion and what are the types of asserts in TestNG? Assertion is used to validate the results of test cases. There are two types of assertion: • HardAssert: HardAssert is used to validate the test result. If hard assert fails, then none of the code execution will take place after Assert statement. Assert.assertEquals(actual value, expected value) • Soft Assert: Soft Assert is also used to validate the test results but if soft assert fails, then also execution of code will be continued for next statements. To create a soft assert, object of “softAssert” class is created: softAssert sAssert = new softAssert(); sAssert.assertAll();
  • 14. TestNG Interview Questions for SDET 13. How to set test case priority in TestNG? Priority attribute is used to set the order of execution of test cases. If priority is not set then the test scripts are executed in alphabetical order. For eg.: Public class PriorityTestCase{ @Test(priority=0) public void testCase1(){ system.out.println(“DLA Test Case 1”); } @Test(priority=1) public void testCase2(){ system.out.println(“DLA Test Case 2”); } } In this case, testCase1 will be executed first and then testCase2 will get execeuted.
  • 15. TestNG Interview Questions for SDET 14. How can we pass parameter to test script using TestNG? We can pass parameter to test scripts by using @Parameter annotation in test and “parameter” tag in testing.xml. Sample testing.xml: <suite name = “dlaTestSuite”> <test name = “dlaTest”> <parameter name = “dlaParamName” value = “dlaParamValue”> <classes> <class name = “dlaTestFile” /> </classes> </test> </suite> Sample Test Script: public class dlaTestFile{ @Test @Parameters(“dlaParamName”) public void dlaParameterTest(string paramValue){ System.out.println(sampleParamName); } }
  • 16. TestNG Interview Questions for SDET 15. How can we create data driven framework using TestNG? To create data driven framework, @DataProvider is used in which data is passed to the associated test method and multiple iteration of tests run for different data values passed from @DataProvider method. For eg.: @DataProvider(name = “dlaDataProvider”) public Object[] [] dataProviderMethod() { return new Object[] [] {{“dev”, “lab”}, {“devlabs”, “alliance”}}; } @Test(dataProvider = “dlaDataProvider”) public void dlaTest(string s1, string s2) { system.out.println(s1 + “ “ + s2); }
  • 17. TestNG Interview Questions for SDET 16. What is the use of @Listener annotation in TestNG? TestNG provides some kinds of listeners using which some actions can be performed in case an event has triggered. Mostly TestNG listeners are used for configuration of reports and logging. The most widely used lisetner in TestNG is ITestListener interface. It contains methods like onTestSuccess, onTestFailure, onTestSkipped etc. To implement this interface, we have to create a listener class of our own. After that @Listener annotation is used to specify that for a particular test class our customized listener class should be used. For eg.: @Listeners(PackageName.CustomizedListenerClassName.class) public class dlaTestClass { WebDriver driver = new FirefoxDriver(); @Test public void dlaTestMethod(){ //test logic }}
  • 18. TestNG Interview Questions for SDET 17. What is the difference between @Factory and @DataProvider annotation? @Factory method creates instances of test class and run all the test methods in that class with different set of data. @DataProvider is bound to individual test methods and run the specific methods multiple times.
  • 19. TestNG Interview Questions for SDET 18. How can we run test cases in parallel using TestNG? To run the tests in parallel in TestNG, we have to add these two key value pairs in suite- • Parallel = "{methods/tests/classes}“ • thread-count= "{number of thread you want to run simultaneously}“ For eg.: <suite name = “DLATestSuite” parallel = “methods” thread-count = “5”>
  • 20. TestNG Interview Questions for SDET 19. How can we make sure a test method runs even if the test methods or groups on which it depends fail or get skipped? To run the test method even if test methods or groups on which it depends get fail or skipped, we use “alwaysRun” attribute of @Test annotation. For eg.: @Test public void parentTest() { Assert.Fail(“Failed Test”); } @Test(dependsOnMethods = {“parentTest”}, alwaysRun = true) Public void DependentTest() { System.out.println(“Test DLA”); }
  • 21. TestNG Interview Questions for SDET 20. How to handle exceptions in TestNG? To handle exception in methods we can mention the exception in @Test annotation so that the test case does not fail. For eg.: If a test method is expected to have “numberFormatException” exception, then the test case will fail because of this exception if no try catch block is specified. But this can be handled in TestNG by using “expectedException” attribute: @Test(expectedException=numberFormatException.class) After this the test case will run without failing.
  • 22. Visit us at: www.devlabsalliance.com Email: training@devlabsalliance.com Contact: +91 9717514555