Sie sind auf Seite 1von 7

TESTNG INTERVIEW QUESTIONS LEVEL- BEGINNER

Question# 1: Can you tell me which unit test framework do you use?
Answer: TestNG
Question# 2: What is TestNG?
Answer: TestNG is a testing framework which is used to make testing activities
simpler, effective, convenient and disciplined.
Question# 3: What does NG mean in TestNG?
Answer: NG stands for ‘Next Generation’. It is the next generation of framework after
Junit.
Question# 4: What are the testing processes are testable with TestNG?
Answer: We use TestNG for the broad range of testing processes from Unit testing to
Integration testing.
Question# 5: What are the importance of using TestNG in our automation
project?
Answer: We use TestNG for the following benefits:
 We define different test activities within annotations
 It supports parallel execution of the test cases
 TestNG supports default threading in parallel execution
 We define dependencies of one test methods/groups over another
 TestNG effectively helps to define test groups
 It supports priority assignment to the Tests
 Parameterizations are easily implemented using @Parameters annotation in
TestNG
 Data-driven testing is efficiently implemented using @DataProvider annotation in
TestNG
 Different types of Assertion commands are available to validate the scenarios
 We can even run TestNG based Selenium projects from the command prompt
 It gives a detailed test report
 TestNG supports retry of failed test cases multiple times
 We can easily implement listeners through ITestListener
 TestNG separately creates an XML file for failed test scenarios
Question# 6: What are different annotations available in TestNG?
Answer: Click here to know details about annotations in TestNG.
Question# 7: How do we run tests created through TestNG?
Answer: We trigger tests through the testng.xml file.
Question# 8: What are the significances of the testng.xml file?
Answer: Followings are the significances of testng.xml file:
 All the tests are triggered by testng.xml file
 It supports inclusion and exclusion of the tests
 Parameters are passed from testng.xml file
 It supports the addition of dependency of groups
 Parallel execution and thread counts are defined in the testng.xml file
 XML creates child XML file for failed tests as testng-failed.xml
Question# 9: Can we run TestNG Selenium project from the command prompt?
Answer: Yes.
Question# 10: What are assertions in TestNG?
Answer: TestNG supports various Assert commands to validate the expected and
actual conditions of the scenarios. Some of the Assert commands in TestNG are as
follows:
 assertEquals(String actual, String expected)
 assertNotEquals(String actual, String expected)
Click here to read more…
TESTNG INTERVIEW QUESTIONS LEVEL- YOUTH
Question# 11: How do we send parameters from a testng.xml file?
Answer: testng.xml support parameterization for @Parameters annotation so we send
values from testng.xml by defining below statement:

1 <parameter name=”name of the parameter” value=”value of the parameter”>


Click here to read more…
Question# 12: Can we handle expected exceptions with TestNG?
Answer: Yes.
Question# 13: How do we handle expected exception with TestNG?
Answer: We use the following statement to handle expected exception with TestNG:

1 @Test(expectedExceptions=ArrayIndexOutOfBoundsException.class)
Question# 14: How do we set the execution priority of the tests?
Answer: We use priority keyword along with @Test annotation to set the priority of the
test. Below statement sets the priority of the test:

1
2
3 @Test(priority=0)
4  
5 public void test1(){
6  
7 }
8  
9  
1  
0 @Test(priority=1)
1  
1 public void test2(){
1  
2 }
1
3
Question# 15: What are different techniques to implement parameterization
in the Selenium project with TestNG?
Answer: We achieve parameterization in Selenium with TestNG by following
techniques:
 Parameterization through @Parameters annotation
 Parameterization through @DataProvider annotation
Question# 16: How do we combine tests with same group identifications?
Answer: We use groups keyword to combine tests of the same group. Here is the
implementation:

1 @Test (groups = {“groupName1”,  “groupName2”})


Question# 17: How to include and exclude groups from testng.xml?
Answer:

1 <groups>
2 <run>
3 <exclude name=”group1”>
4 <include name=”group2”>
5 </include>
6 </exclude>
7 </run>
8 </groups>
Click here to know more…
Question# 18: How are tests run in parallel in TestNG?
Answer: We use “parallel” keyword to run tests in parallel.
Question# 19: How to starts different threads in parallel in TestNG?
Answer: We give integer value to the keyword “thread-count” in the testng.xml file to
start multiple threads in parallel.
Question# 20: What are parallel attributes in TestNG?
Answer: Parallel keyword has following attributes to trigger tests in parallel:
 tests
 classes
 methods
 instances
 true
 false
Question# 21: How to skip tests at runtime with TestNG?
Answer: We throw SkipExceotion(String message) to skip tests at runtime.
Click here to know more…
Question# 22: Can we ignore some tests with TestNG?
Answer: Yes.
Question# 23: How to ignore tests with TestNG?
Answer: We use the following statement with the @Test annotation to ignore tests with
TestNG.
1 @Test(enabled=false)
Question# 24: How to define dependencies with TestNG?
Answer: We use the dependsOnMethods keyword to define dependencies with TestNG.
Click here to read in detail…

TESTNG INTERVIEW QUESTIONS LEVEL- LEGEND


Question# 25: How to design a data-driven framework using TestNG?
Answer: We use @DataProvider annotation to design data-driven framework in
Selenium with TestNG.
Click on below link to know more.

How to create a data-driven framework with TestNG?


Question# 26: What is the return type of method within @DataProvider
annotation?
Answer: Method implemented with @DataProvider annotation has 2-D Object as its
return type.
Question# 27: How to perform advanced logging in Selenium with TestNG?
Answer: We use Test listeners to implement advanced logging with TestNG.
Question# 28: What are TestNG Listeners?
Answer: TestNG listeners are used for intelligent and advanced reporting and logging
in the Selenium project. We implement TestNG listeners by following ways:
 TestNG listener implementation by- @Listener annotation
 TestNG listener implementation through the testng.xml file
Question# 29: What is the difference between listener implementation
through @Listener annotation and through the testng.xml file?
Answer: TestNG listener implementation through @Listener annotation is restricted to
a particular class only, whereas, listener implementation through the testng.xml file is
applicable to the entire test suite.
Question# 30: How to implement TestNG listener through the testng.xml file?
Answer: We add following statement in testng.xml file to implement TestNG listener.
1 <listeners>
2 <listener class-name=”Class_Name”/>
3 </listeners>
Question# 31: What are the listeners’ name for logging and reporting in
TestNG?
Answer: We implement ITestListener for effective logging and IReporter listeners for
custom reporting in TestNG.
Here is the tutorials link for their implementation:

 How to create a custom TestNG report using IReporter?


 How to implement ITestListener in Selenium?
Question# 32: What is the interface name to implement test retry with
TestNG?
Answer: We implement IRetryAnalyzer and IAnnotationTransformer interfaces to
implement retry of failed tests with TestNG.
 How to retry failed tests with TestNG?
Question# 33: How to define a regular expression in the testng.xml file to
search tests which contain keyword “regression”?
Answer:

1 <methods>
2                 <include name=”.*regression.*”/>
3 </methods>
Question# 34: What is the time unit to define in test suites?
Answer: milliseconds.
Question# 35: How to run particular test methods multiple times?
Answer: we use the following statement to invoke particular tests for a certain number
of times.

1 @Test(invocationCount = 20)
2 public void myTest(){

4}
Question# 36: How to run a test method from multiple different threads?
Answer: Following code specifies that myTest() method will be invoked from 5 different
threads.
@Test (threadPoolSize = 5, <code class=”My Class”>invocationCount = </code><code
1
class=”value”>20</code>)
2
public void myTest(){
3
 
4
}
Question# 37: How to give timeouts to different threads with TestNG?
Answer: We use ‘timeOut’ keyword to add the time delay. Here is the statement:

1 @Test (threadPoolSize = 5, invocationCount = 20, timeOut = 20000)


2 public void myTest(){

4}
Question# 38: What is the use of @Factory annotation in TestNG?
Answer: @Factory annotation helps to run different classes from a sing class. It is also
used to set the value of the parameterized constructor with the help of @DataProvider
annotation.
Click here to read more on @Factory annotation implementation…
Question# 39: What is the return type of method written within @Factory
annotation?
Answer: The return type of the method written within @Factory annotation is 1D
Object array.
Question# 40: What is the command to run TestNG using command prompt?
Answer:

1 set classpath=pathOfBinFolder/bin; pathOfLibFolder/lib/*;


2 java org.testng.TestNG pathOftestng.xml/testng.xml

TESTNG INTERVIEW QUESTIONS LEVEL-


MISCELLANEOUS
Here are some of the miscellaneous TestNG interview questions which are generally not
asked in an interview, but you should have knowledge of it.

Question# 41: Which version of TestNG have you used in your previous
project?
Question# 41: How did you install TestNG in your IDE?
Question# 42: Which IDE did you use for TestNG?
Question# 43: Have you extended your existing testng.xml file with another
testng.xml file?
Question# 44: When did TestNG come in picture?
Question# 45: Who developed TestNG?
Question# 46: How is TestNG better than Junit?
Question# 47: What is the folder name generated after the first test run
through the testng.xml file?
Question# 48: What is emailable-report in TestNG?
Question# 49: Can we pass a large set of parameters through @Parameters
annotation?
Question# 50: How to perform inheritance in the testng.xml file?
These are all about TestNG Interview Questions. You may join our Facebook group for
more updates on Selenium and TestNG. Click below link to know more about TestNG.

 TestNG Tutorials
 Selenium Interview Questions
 

Share

Das könnte Ihnen auch gefallen