YouTube Icon

Interview Questions.

Top 100+ Testng Interview Questions And Answers - Jun 02, 2020

fluid

Top 100+ Testng Interview Questions And Answers

Question 1. What Is Testng?

Answer :

TestNG is a checking out framework designed to simplify a broad range of trying out wishes, from unit checking out to integration checking out.

Question 2. What Are The Advantages Of Testng?

Answer :

TestNG affords parallel execution of test strategies
It allows to outline dependency of one test approach over other approach
It allows to assign precedence to check techniques
It allows grouping of test strategies into take a look at groups
It has assist for parameterizing check cases using @Parameters annotation
It lets in statistics driven checking out the usage of @DataProvider annotation
It has one of a kind assertions that helps in checking the expected and real effects
Detailed (HTML) reviews
Adv Java Interview Questions
Question three. What Are The Annotations Available In Testng?

Answer :

@BeforeTest
@AfterTest
@BeforeClass
@AfterClass
@BeforeMethod
@AfterMethod
@BeforeSuite
@AfterSuite
@BeforeGroups
@AfterGroups
@Test
Question four. How To Create And Run Testng.Xml?

Answer :

In TestNG framework, we want to create testng.Xml record to create and cope with a couple of check lessons. We do configure our check run, set test dependency, consist of or exclude any test, method, elegance or bundle and set precedence and so forth in the xml record.

Adv Java Tutorial
Question 5. What Is The Importance Of Testng.Xml File?

Answer :

In a Selenium TestNG venture, we use testng.Xml record to configure the entire take a look at suite in a single document.

Some of the functions are as follows:

testng.Xml report permits to consist of or exclude the execution of check methods and check corporations
It allows to bypass parameters to the check instances
Allows to feature group dependencies
Allows to feature priorities to the test cases
Allows to configure parallel execution of test cases
Allows to parameterize the check instances
Core Java Interview Questions
Question 6. How To Pass Parameter Through Testng.Xml File To A Test Case?

Answer :

We may want to outline the parameters within the testng.Xml file and then reference those parameters inside the supply documents.

Create a java check elegance, say, ParameterizedTest.Java and upload a check approach say parameterizedTest() to the take a look at magnificence. This approach takes a string as input parameter. Add the annotation @Parameters(“browser”) to this technique.

// TestNG Interview Questions
public magnificence ParameterizedTest 
@Test
@Parameters("browser")
public void parameterizedTest(String browser)
if(browser.Equals("firefox"))
System.Out.Println("Open Firefox Driver");
else if(browser.Equals("chrome"))
System.Out.Println("Open Chrome Driver");

The parameter could be passed a price from testng.Xml, which we will see within the next step.

We may want to set the parameter using the under syntax in the testng.Xml file. 

<parameter name="browser" value="firefox"/>

Here, name characteristic represents the parameter call and cost represents the fee of that parameter.

Question 7. What Is Testng Assert And List Out Common Testng Assertions?

Answer :

TestNG Asserts help us to verify the situation of the take a look at in the center of the take a look at run. Based at the TestNG Assertions, we are able to consider a a success test only if it's far finished the test run without throwing any exception.

Some of the not unusual assertions supported via TestNG are:

assertEqual(String actual,String predicted)
assertEqual(String actual,String expected, String message)
assertEquals(boolean real,boolean expected)
assertTrue(situation)
assertTrue(circumstance, message)
assertFalse(condition)
assertFalse(situation, message)
Core Java Tutorial Testing Tools Interview Questions
Question eight. What Is Soft Assert In Testng?

Answer :

Soft Assert collects mistakes in the course of @Test. Soft Assert does not throw an exception when an assert fails and would preserve with the next step after the assert assertion.

If there's any exception and you need to throw it then you need to use assertAll() technique as a final declaration in the @Test and take a look at suite once more retain with next @Test as it's miles.

Question nine. What Is Hard Assert In Testng?

Answer :

Hard Assert throws an AssertException immediately whilst an assert assertion fails and check suite keeps with next @Test.

QTP Interview Questions
Question 10. What Is Exception Test In Testng?

Answer :

TestNG offers an choice for tracing the Exception dealing with of code. You can confirm whether a code throws the anticipated exception or not. The predicted exception to validate at the same time as going for walks the check case is mentioned the use of the expectedExceptions characteristic value in conjunction with @Test annotation.

Testing Tools Tutorial
Question 11. How To Set Test Case Priority In Testng?

Answer :

We use priority attribute to the @Test annotations. In case priority isn't set then the take a look at scripts execute in alphabetical order.

// TestNG Interview Questions
bundle TestNG;
import org.Testng.Annotations.*;
public class PriorityTestCase
@Test(precedence=zero)
public void testCase1()   
gadget.Out.Println("Test Case 1");

@Test(priority=1)
public void testCase2()   
gadget.Out.Println("Test Case 2");


Output:

Test Case 1
Test Case 2
Manual Testing Interview Questions
Question 12. What Is Parameterized Testing In Testng?

Answer :

Parameterized assessments allow builders to run the equal take a look at time and again again the usage of extraordinary values.

There are  methods to set those parameters:

the use of testng.Xml 
the use of Data Providers
Adv Java Interview Questions
Question thirteen. How Can We Create Data Driven Framework Using Testng?

Answer :

By using @DataProvider annotation,  we are able to create a Data Driven Framework.

@DataProvider(call="getData")
public Object[][] getData()
//Object [][] data = new Object [rowCount][colCount];
Object [][] statistics = new Object [2][2];
facts [0][0] = "FirstUid";
information [0][1] = "FirstPWD";
information[1][0] = "SecondUid";
facts[1][1] = "SecondPWD";
return statistics;

QTP Tutorial
Question 14. How To Run A Group Of Test Cases Using Testng?

Answer :

TestNG lets in you to carry out state-of-the-art groupings of take a look at techniques. Not best can you claim that techniques belong to corporations, however you could additionally specify groups that incorporate other groups. Then TestNG may be invoked and requested to encompass a certain set of companies (or normal expressions) whilst except every other set.  This offers you most flexibility in how you partition your exams and doesn’t require you to recompile some thing in case you need to run  extraordinary sets of assessments again to lower back.

Groups are specified in your testng.Xml report and may be located either below the <test> or <suite> tag. Groups particular in the <suite> tag apply to all of the <test> tags beneath.

@Test (organizations =  "smokeTest", "functionalTest" )
public void loginTest()
System.Out.Println("Logged in efficaciously");

Question 15. How To Create Group Of Groups In Testng?

Answer :

Groups can also include different businesses. These groups are called MetaGroups. For instance, you might want to outline a set all that includes smokeTest and functionalTest.

Let’s regulate our testng.Xml record as follows:

<groups>
   <define name="all">
 <include name="smokeTest"/>
 <include name="functionalTest"/>
   </define>
   <run>
         <include name="all" />
   </run>        
</groups>
Selenium Interview Questions
Question sixteen. How To Run Test Cases In Parallel Using Testng?

Answer :

we can use “parallel” characteristic in testng.Xml to perform parallel check execution in TestNG

The parallel attribute of suite tag can receive four values:

exams: All the take a look at cases inner <test> tag of testng.Xml record will run parallel

lessons: All the check instances interior a java elegance will run parallel

methods: All the methods with @Test annotation will execute parallel

times: Test cases in identical example will execute parallel however two techniques of two exclusive times will run in one-of-a-kind thread.

<suite name="softwaretestingmaterial" parallel="methods">

Selenium Tutorial
Question 17. How To Exclude A Particular Test Method From A Test Case Execution?

Answer :

By including the exclude tag inside the testng.Xml

<classes>
  <class name="TestCaseName">
     <methods>
       <exclude name="TestMethodNameToExclude"/>
     </methods>
  </class>      
</classes>
Automation Testing Interview Questions
Question 18. How To Exclude A Particular Test Group From A Test Case Execution?

Answer :

By including the exclude tag inside the testng.Xml

<groups>
    <run>
 <exclude name="TestGroupNameToExclude"/>
    </run>      
</groups>
Core Java Interview Questions
Question 19. How To Disable A Test Case In Testng?

Answer :

To disable the check case we use the parameter enabled = false to the @Test annotation.

@Test(enabled = fake)

Software trying out Tutorial
Question 20. How To Skip A @check Method From Execution In Testng?

Answer :

By using throw new SkipException()

Once SkipException() thrown, ultimate a part of that check method will not be accomplished and manipulate will goes immediately to next take a look at technique execution.

Throw new SkipException("Skipping - This is not prepared for trying out ");
Software checking out Interview Questions
Question 21. How To Ignore A Test Case In Testng?

Answer :

To forget about the test case we use the parameter enabled = false to the @Test annotation.

@Test(enabled = false)
Question 22. How Testng Allows To State Dependencies?

Answer :

TestNG lets in two methods to claim the dependencies.
Using attributes dependsOnMethods in @Test annotations 
Using attributes dependsOnGroups in @Test annotations 
JUnit Tutorial
Question 23. What Are The Different Ways To Produce Reports For Testng Results?

Answer :

TestNG offers  approaches to produce a report:

Listeners put in force the interface org.Testng.ITestListener and are notified in real time of while a take a look at starts, passes, fails, and so on…

Reporters enforce the interface org.Testng.IReporter and are notified whilst all the suites were run by TestNG. The IReporter example gets a listing of items that describe the whole check run.

JUnit Interview Questions
Question 24. What Is The Use Of @listener Annotation In Testng?

Answer :

TestNG listeners are used to configure reports and logging. One of the most widely used listeners in testNG is ITestListener interface. It has strategies like onTestStart, onTestSuccess, onTestFailure, onTestSkipped and so forth. We have to enforce this interface developing a listener class of our personal. Next we need to upload the listeners annotation (@Listeners) in the Class which became created.

Testing Tools Interview Questions
Question 25. How To Write Regular Expression In Testng.Xml File To Search @check Methods Containing “smoke” Keyword.?

Answer :

Regular expression to discover @Test strategies containing keyword “smoke” is as stated below.

<methods>
     <include name=".*smoke.*"/>
</methods>
Software Development Lifecycle (SDLC) Tutorial
Question 26. What Is The Time Unit We Specify In Test Suites And Test Cases?

Answer :

We specify the time unit in test suites and take a look at instances is in milliseconds.

DataGrid Interview Questions
Question 27. List Out Various Ways In Which Testng Can Be Invoked?

Answer :

TestNG may be invoked within the following methods:

Using Eclipse IDE
Using ant build tool
From the command line
Using IntelliJ’s IDEA
QTP Interview Questions
Question 28. How To Run Testng Using Command Prompt?

Answer :

Run the TestNG using command prompt

Open command activate and use the beneath code

C:UsersAdminDesktopSTMSeleniumTutorialworkspaceSoftwareTestingMaterial
set classpath=C:UsersAdminDesktopSTMSeleniumTutorialworkspaceSoftwareTestingMaterialbin;C:UsersAdminDesktopSTMSeleniumTutorialworkspaceSoftwareTestingMateriallib*
java org.Testng.TestNG C:UsersAdminDesktopSTMSeleniumTutorialworkspaceSoftwareTestingMaterialtestng.Xml
Question 29. What Is The Use Of @check(invocationcount=x)?

Answer :

The invocationcount characteristic tells how frequently TestNG have to run a take a look at method

@Test(invocationCount = 10)
public void testCase1()
In this example, the method testCase1 might be invoked ten times.

Selenium WebDriver Interview Questions
Question 30. What Is The Use Of @check(threadpoolsize=x)?

Answer :

The threadPoolSize attribute tells to form a thread pool to run the check approach through a couple of threads.

Note: This attribute is left out if invocationCount isn't always particular

@Test(threadPoolSize = three, <code class="plain">invocationCount = </code><code class="value">10</code>)
public void testCase1()
In this situation, the approach testCase1 might be invoked from three specific threads.

Question 31. What Does The Test Timeout Mean In Testng?

Answer :

The most range of milliseconds a test case must take.

@Test(threadPoolSize = three, invocationCount = 10,  timeOut = 10000)
public void testCase1()
In this case, the function testCase1 will be invoked ten times from three special threads. Additionally, a time-out of ten seconds guarantees that not one of the threads will block in this thread all the time.

Question 32. What Are @manufacturing facility And @dataprovider Annotation?

Answer :

@Factory: A factory will execute all the test strategies gift inside a test class the usage of a separate instance of the respective elegance with exceptional set of information.

@DataProvider: A test approach that uses DataProvider might be completed the particular methods a couple of variety of times based on the statistics supplied through the DataProvider. The take a look at approach will be carried out the usage of the same instance of the take a look at magnificence to which the take a look at technique belongs.

Selenium IDE Interview Questions




CFG