TestNG is a testing framework created by Cedric Beust.
This is inspired from Junit and Nunit.
In the TestNG ng stangs Next Generation.
This is used to cover almost all the categories of testing like unit, end to end,functional,integration etc.
WhyTestNG, why not Junit ?
Before TestNG this was difficult to know about how many test cases have been executed, pass,fail and skip.TestNG gives us this feature to know about how many test cases have been executed, pass,fail and skip.
TestNG is almost same as Junit but it overcomes the limitations of Junit and provides more functionality than junit for example junit is only used for unit testing while TestNG covers almost all kinds of testing categories.Most of the selenium user prefer TestNG over junit because of its features.This is using widely in the market.
Advantages of TestNG:
The prior advantage of TestNG is to provide predefined annotations.
It provides a feature to generate the well defined HTML reports.
With the help of TestNG we can group our test cases,for example if i have to execute only regression suite so i can group all the regression test cases and with the help of @Test(groups="Regression") statement and will define in the testng.xml inside the tag.
We can do parallel testing.
TestNG uses more Java and OO features.
Support for multithreaded testing.
Types of Annotations :
@Test: The annotated method is a part of a test case.
@BeforeSuite: The annotated method will be run before all tests in this suite have run.
@AfterSuite: The annotated method will be run after all tests in this suite have run.
@BeforeTest: The annotated method will be run before any test method belonging to the classes inside the tag is run.
@AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the tag have run.
@BeforeGroups: The list of groups that this configuration method will run before. This method is guaranteed to run shortly before the first test method that belongs to any of these groups is invoked.
@AfterGroups: The list of groups that this configuration method will run after. This method is guaranteed to run shortly after the last test method that belongs to any of these groups is invoked.
@BeforeClass: The annotated method will be run before the first test method in the current class is invoked.
@AfterClass: The annotated method will be run after all the test methods in the current class have been run.
@BeforeMethod: The annotated method will be run before each test method.
@AfterMethod: The annotated method will be run after each test method.
Example of writing test cases with various annotations :-
Installing the TestNG :
We simply can copy the dependency from the below url and paste it into the pom.xml file.
Or Download the plug, please follow the below steps .
1) Launch the Eclipse IDE and from Help menu, click “Install New Software”.
2) You will see a dialog window, click “Add” button.
3) Type name as you wish, lets take “TestNG” and type “http://beust.com/eclipse/” as location. Click OK.
4) You come back to the previous window but this time you must see TestNG option in the available software list. Just Click TestNG and press “Next” button.
5) Click “I accept the terms of the license agreement” then click Finish.
6) You may or may not encounter a Security warning, if in case you do just click OK.
7) Click Next again on the succeeding dialog box until it prompts you to Restart the Eclipse.
8) You are all done now, just Click Yes.
9) Proceed with your workplace.
10) After restart, verify if TestNG was indeed successfully installed. Right click on you project and see if TestNG is displayed in the opened menu.
What is ReportNG :-
This is just a plug in for the TestNG unit-testing framework. The default report is hard to understand also not in the prescribed manner and can’t be shown to the managers. so ReportNG overcomes this limitation of testNG.ReportNG provides a simple, colour-coded view of the test results.
Installation Steps for ReportNG:-
Copy the below dependency and paste it into the pom.xml file and save the pom.xml.
Or you also can get this dependency from the below link as well.
2. After saving the pom.xml you will find the ReportNG jar file as shown in below figure.
To make your reports more interactive,decent and readable you can add below add-ons(dependencies) also.
OR download it from below link.