TestNG Framework Introduction


TestNG is an open source automated testing framework. TestNG is similar to JUnit but it is much more powerful than JUnit with advanced annotations.

Advantages of TestNG :

Simple Annotations.
Test cases can be Grouped & Prioritized more easily.


Test that your code is multithread safe.
Using XML do Flexible test configuration.
Support for data-driven testing (with @DataProvider).
Parallel testing is possible.
Compatibility testing (Browsers specific)
Auto-Report Generation (HTML).
Supported ignore, time, parameters, Suite and exception Test.
Supported by Eclipse, IDEA, Ant, Maven, Netbean, Jenkins, Hudson and so on.

Annotations in TestNG :

@BeforeSuite: Method marked with @BeforeSuite annotation will run before the all suites from test.

@AfterSuite: @AfterSuite annotated method will start running when execution of all tests executed from current test suite.
@BeforeTest: @BeforeTest annotated method will be executed before the any @Test annotated method of those classes which are inside <test> tag in testng.xml file.
@AfterTest: @AfterTest annotated method will be executed when all @Test annotated methods completes its execution of those classes which are inside <test> tag in testng.xml file.
@BeforeGroups: @BeforeGroups annotated method will run before the first test run of that specific group.
@AfterGroups: @AfterGroups annotated method will run after all test methods of that group completes its execution.
@BeforeClass: Method annotated using @BeforeClass will be executed before first @Test method execution. @BeforeClass annotated method will be executed once only per class so don’t be confused.
@AfterClass: Method annotated with @AfterClass annotation will be executed once only per class after execution of all @Test annotated methods of that class.
@BeforeMethod: Any method which is marked with @BeforeMethod annotation will be executed before each and every @test annotated method.
@AfterMethod: If any method is annotated with @AfterMethod annotation then it will be executed after execution of each and every @test annotated method.
@Test: @Test annotation describes method as a test method or part of your test.

@DataProvider
When you use @DataProvider annotation for any method that means you are using that method as a data supplier. Configuration of @DataProvider annotated method must be like it always return Object[][] which we can use in @Test annotated method.
@Parameters
When you wants to pass parameters in your test methods, you need to use @Parameters annotation.
@Factory
When you wants to execute specific group of test cases with different values, you need to use @Factory annotation. An array of class objects is returned by @Factory annotated method and those TestNG will those objects as test classes.
@Listeners
@Listeners are used to with test class. It is helpful for logging purpose.

Install TestNG Eclipse plug-in

How to install TestNG plug-in can be found here
Installation Guide

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s