Thursday 14 August 2014

Introduction Of TestNG




-> TestNG is unit testing framework. and its most popular among all java developers and selenium webdriver automation test engineers.

-> TestNG's development is inspired from combination of NUnit and JUnit. Its have all features from JUnit and also its have more features comapare to JUnit.



TestNG Annotations

-> The main reason behind TestNG's popularity is we can create and configure test case and test suite very easily using many different annotations of TestNG.

-> Few annotations are similiar with JUnit. Also its have more annotations.

-> Annotations in TestNG are which guides you what to do next or which method should be exeute next.

-> TestNG has also facility to pass parameters with annotations.


1) @Test
2) @BeforeMethod
3) @AfterMethod
4) @BeforeClass
5) @AfterClass
6) @BeforeTest
7) @AfterTest
8) @BeforeSuite
9) @AfterSuite
10) @DataProvider
11) @BeforeGroups
12) @AfterGroups
13) @Parameters
14) @Factory
15) @Listeners



1) @Test

-> Generally method under @Test used to write all testing related activity.
-> We can have any number of @Test method in single class of our test.



2) @BeforeMethod

-> Any Method which its marked as BeforeMethod will execute before each and every @Test Method Annotations.
-> Generally method under @BeforeMethod used to initializing browser or environment related setup.
-> The method under @BeforeMethod annotation will executed before each @Test annotations. That means if we have four @Test annotaions in your class, then the @BeforeMethod will execute four times.
-> Its same as @Before annoation in JUnit.



3) @AfterMethod

-> Any Method which its marked as BeforeMethod will execute after each and every @Test Method Annotations.
-> Generally method under @BeforeMethod used to close the instances.
-> The method under @AfterMethod annotation will executed after each @Test annotations. That means if we have four @Test annotaions in your class, then the @AfterMethod will execute four times.
-> Its same as @After annoation in JUnit.



4) @BeforeClass

-> Methods under @BeforeClass will execute before any one of the first test method starts execution.
-> It will execute only once even if there are multiple @Test method in our class.



5) @AfterClass

-> The method under @AfterClass will execute all the completion of @Test methods exection in class.
-> It will execute only once even if there are multiple @Test method in our class.



6) @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.



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



8) @BeforeSuite

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



9) @AfterSuite

-> @AfterSuite annotated method will start running when execution of all tests executed from current test suite.



10) @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.
VIEW PRACTICAL EXAMPLE OF @DataProvider ANNOTATION


11) @BeforeGroups

@BeforeGroups annotated method will run before the first test run of that specific group.


12) @AfterGroups

@AfterGroups annotated method will run after all test methods of that group completes its execution.


13) @Parameters

When you wants to pass parameters in your test methods, you need to use @Parameters annotation.
VIEW PRACTICAL EXAMPLE OF @Parameters ANNOTATION


14) @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.

 
15) @Listeners

@Listeners are used to with test class. It is helpful for logging purpose.



Major Features


1) TestNG has a built in multiple Before and After and other annotations like @BeforeSuite, @AfterSuite, @BeforeTest, @BeforeGroups, @DataProvider, @Parameters, @Test etc.. All the TestNG annotations are very easy to understand and implement.

2) we can configure dependent test method. That means Test1() is dependent to Test2(). or else if test we cn configure if test1() is fail means Test1() has to be execute or not.

3) There is not required to extend any class in TestNG

4) We can configure our test suite using test methods, classes, packages, groups, etc.. in single testng.xml file.

5) Support of configuring test groups like backendtest-group, frontendtest-group etc..

6) we can also tell TestNG to execute only specific group/groups.

7) TestNG is supported by many tools and plug-ins like Eclipse, Maven, IDEA, etc..

8) TestNG has built in HTML report and XML report generation facility. It has also built in  logging facility.

9) Support for data-driven testing (with @DataProvider).

10) Flexible test configuration.

11) Ability to re-execute failed test cases.

12) TestNG also supports
-> parallel testing
-> Parameterization (Passing parameters values through XML configuration)
-> Data Driven Testing(executing same test method multiple times using different data)



No comments:

Post a Comment