What is TestNG and Why we have to use in Selenium

What is TestNG and Why we have to use in Selenium

Ans- TestNG is a testing framework which is designed to cover all categories of tests: unit, functional, end-to-end, integration, etc…

We can combine TestNG with Selenium and we can write Test Cases in Eclipse using Java.

1-TestNG,Junit,Nunit are a separate testing framework which is freely available in the market.

2-TestNG,Junit mainly we can integrate into Java whereas Nunit works with C# only.

3-Junit comes by default with Eclipse but TestNG you have to install an Add-ons.

4-Junit has fewer annotations as compared to TestNG.

5-Junit automatically does not create HTML report so we have to use ant build tool, but TestNG has rich HTML report generations even for single test case it creates 3 HTML reports

TestNG features:

1- Annotation- It support multiple annotations at a various level

2- Support for data-driven testing (with @DataProvider)

3- Support for parameters.

4- Generate automatic reports

5- We can run failed test case only using testng.xml no need to run the full test suite in case of failure

6- Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc…).

7- Default JDK functions for runtime and logging (no dependencies).

8- Dependent methods for application server testing. Configure TestNG with Eclipse

Difference between Java Program and TestNg Script

Ans- When we execute Java program and TestNG script then functionality wise nothing will change because our script is performing the same functionality but using TestNG you will get some additional functionality.

Some benefit of TestNG Script

1- For even single test case you will get 3 reports. These reports generated by TestNG

2-You can check execution time i.e. How much time test case has taken

3-Parallel execution etc

How we can write TestNG Script?

Ans- To execute TestNG script we don’t have to write the separate class. We can use simple java class but here we will not write public static void main(String []args) because we are not going to execute this from JVM.

TestNG works with Annotations and annotation can be represented by @ symbol

@Test- is this the main annotation from where TestRunner will start execution. In other words, you can say @Test in entry point

Step 1- Select your project

Step 2- Go to src and create a new package and give any name

Step 3- Now select above created package and create a new class and give any name (I gave Program1)

Step 4- create a simple java method and before that method use @ Test (in my case I have written 3 test case)

Importance of Reporting in Selenium

1- Reports help you to identify the status of the test case (Pass/Fail/Skip).

2- Using reports we calculate time taken by each test case that helps to calculate ROI (Return on Investment).

3- You can share automation reports with your team and clients as well to share the status of testing progress etc.

@BeforeMethod- //@BeforeMethod defines this method has to run before every @Test methods

@AfterMethod- //@AfterMethod defines this method has to run after every @Test methods

Last updated