Kick Start With TestNG — Chapter 1-Automation Testing Overview
Introduction
Testing is a mechanism to verify and validate the “System in consideration is performing as per the requirements and is available to its intended users when its suppose to be”. To learn more about testing, click here.
Testing can be done manually or through Automation.
Why Automation?
Testing is a forever going process because as the product ages , new functionalities are extended and bugs are fixed, the number of test cases grow exponentially. Doing all the test cases manually can have the following disadvantages.
1- Time consuming.
2- Open to Human errors.
3- Repetitive work.
4- Not all tests are covered always.
5- Delay in deploying latest build to the production.Having someway to reduce the above factors can drastically increase productivity and efficiency in the entire software development and delivery process. The only solution is “Automation”.
Why TestNG?
Great ! We now know why automation is a necessity in a robust world of ours, but why TestNG?
To write efficient and effective automation code, we need a automation framework which can help us avoid DRY and not just organize our code and tests but also enable us to run our test with ease and customizable to our requirements. TestNG provides all this and after all, the “NG” does stand for “NEXT GENERATION”.
TestNG
TestNG is a framework that helps us organize our tests, control the test flow with the help of annotations, provide test reports and logs for tracking and analysis. It also supports parallel testing aka Simultaneous Testing.
Features of TestNG
(1) Annotations
The flow of test script is controlled by the help of annotations. Annotations in TestNG are also used to transform normal functions to data providing function or to pass values to the test methods.
Annotations are prefixed by “@” and then the keyword such as test, for example @Test, @Parameters, @DataProvider etc.
(2) Test Life Cycle
The test life cycles are managed through life cycle annotations. These are used to manage what happens before and after each test and also for the main suite as well.
Following are the life cycle annotations with the order they are executed.
- @BeforeSuite ( Runs before all the tests in the suite are invoked )
- @BeforeTest ( Runs before all the tests in the test tag of this class are invoked)
- @BeforeClass ( Runs before the first test of the this class is invoked)
- @BeforeGroup ( Runs before the first test of the this group is invoked)
- @BeforeMethod ( Runs before all the tests of the this class are invoked)
- [ Execution of all test Methods. ]
- @AfterMethod ( Runs after all the tests of the this class are invoked)
- @AfterGroup ( Runs after all the tests of the this class are invoked)
- @AfterClass ( Runs after the first test of the this class is invoked)
- @AfterTest ( Runs after all the tests in the test tag of this class are invoked)
- @AfterSuite ( Runs after all the tests in the suite are invoked )
(3) Attributes
The attributes are associated with an annotation and they help in understanding and better controlling of functionality for the method they are associated with.
Few of the most used attributes are as follows.
- name
- description
- timeOut
- priority
- dependsOnMethods
- enabled
- groups
- date-provider
- expectedExceptions
- expectedExceptionsMessageRegExp
(4) XML Configurations
The suite can be configured and executed in a XML configuration file.
Using this method, we have vast control and power over the test suite as be can arrange tests in groups, exclude or include tests, methods, groups or even classes etc. .
(5) Parallelism
With the help of parallel test execution support of TestNG, we can perform multiple tests simultaneously. We can even execute multiple classes, methods, tests or groups.
Further Notes:
This will be completed set of articles for getting started with TestNG. The article list below will be updated periodically. Click on the link to get started !
0 - Understanding Software Testing And Types.
i - Kick Start With TestNG — Chapter 1- Automation Testing Overview.
ii - Kick Start With TestNG — Chapter 2- Setting Up TestNG First Project In Eclipse IDE.
iii - Kick Start With TestNG — Chapter 3- Error Handling with Annotation and Asserts.