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 :-

  1. Annotations of TestNG are easy to understand.

  2. Using TestNG Test cases can be grouped easily.

  3. 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:-

  1. @BeforeSuite:- The method which is annotated with @BeforeSuite annotation will be execute before all tests in this suite.

  2. @AfterSuite:- The method which is annotated with @AfterSuite annotation will be execute after all tests in this suite.

  3. @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.

  4. @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.

  5. @BeforeGroups:- The list of groups that this method will run before.

  6. @AfterGroups:- The list of groups that this method will run after.

  7. @BeforeClass:- The method which is annotated with @BeforeClass annotation will be execute before the first test method in the class.

  8. @AfterClass:- The method which is annotated with @AfterClass annotation will be execute after all the test methods.

  9. @BeforeMethod:- The method which is annotated with @BeforeMethod annotation will be execute before each test method.

  10. @AfterMethod:- The method which is annotated with @AfterMethod annotation will be execute after each test method.

  11. @Test:- The method which is annotated with @Test annotation method is a part of a test case.

 

Related Tags

About Author

Author Image
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.

Request for Proposal

Name is required

Comment is required

Sending message..