Brief About TestNG
Posted By : Neha Saini | 22-Jan-2018
TestNG is a framework for Testing that is used to overcomes the disadvantage of another testing framework called Junit. The meaning of “NG” is "Next Generation."
Selenium users use the TestNG framework more than the Junit because of the TestNG advantages.
Advantages of TestNG over Junit :-
-
Annotations of TestNG are easy to understand.
-
Using TestNG Test cases can be grouped easily.
-
Testing can be done Parallel.
Annotations in TestNG are the lines of code that can control the execution of the methods.. Annotations are always preceded by the @ symbol.
Two Example of Annotations:-
@Test(priority = 0)
public void gotoHomepage()
{
driver.get(url);
Assert.assertEquals(driver.getTitle(),"Welcome");
}
@Test(priority = 1)
public void logout()
{
driver.findElement(By.linkText("SIGN-OFF")).click();
Assert.assertEquals("Sign-on",driver.getTitle());
}
Test(priority = 0)
public void gotoHomepage()
{
driver.get(url);
Assert.assertEquals(driver.getTitle(),"Welcome");
}
@Test(priority = 1)
public void logout()
{
driver.findElement(By.linkText("SIGN-OFF")).click();
Assert.assertEquals("Sign-on",driver.getTitle());
}
Annotations in TestNG:-
-
@BeforeSuite:- The method which is annotated with @BeforeSuite annotation will be execute before all tests in this suite.
-
@AfterSuite:- The method which is annotated with @AfterSuite annotation will be execute after all tests in this suite.
-
@BeforeTest:- The method which is annotated with @BeforeTest annotation will be execute before any test method that is belonging to the classes inside the tag is run.
-
@AfterTest:- The method which is annotated with @AfterTest annotation will be execute after all the test methods belonging to the classes inside the tag is run.
-
@BeforeGroups:- The list of groups that this method will run before.
-
@AfterGroups:- The list of groups that this method will run after.
-
@BeforeClass:- The method which is annotated with @BeforeClass annotation will be execute before the first test method in the class.
-
@AfterClass:- The method which is annotated with @AfterClass annotation will be execute after all the test methods.
-
@BeforeMethod:- The method which is annotated with @BeforeMethod annotation will be execute before each test method.
-
@AfterMethod:- The method which is annotated with @AfterMethod annotation will be execute after each test method.
-
@Test:- The method which is annotated with @Test annotation method is a part of a test case.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Neha Saini
Neha is a QA Engineer in Oodles and have good knowledge of Manual Testing and Automation Testing , always eager to learn new things.