Conclusion Through this tutorial, we tried to make you acquainted with a java based testing framework named as TestNG. We started off the session with the installation of the framework and moved with the script creation and advance topics. We discussed all the annotations provided by TestNG. We implemented and executed our first TestNG test script using annotations and assert statements. Article summary: - TestNG is an advance framework designed in a way to leverage the benefits by both the developers and testers.
- TestNG is an open source framework which is distributed under the Apache software License and is readily available for download.
- TestNG is considered to be superior to JUnit because of its advance features.
- Features of TestNG
- Support for Annotations
- Advance execution methodology that do not require test suites to be created
- Support for parameterization
- Support for Data Driven Testing using Dataproviders
- Setting execution priorities for the test methods
- Supports threat safe environment when executing multiple threads
- Readily supports integration with various tools and plug-ins like build tools (Ant, Maven etc.), Integrated Development Environment (Eclipse).
- Facilitates user with effective means of Report Generation using ReportNG
- Advantages of TestNG over JUnit
- Added advance and easy annotations
- Execution patterns can be set
- Concurrent execution of test scripts
- Test case dependencies can be set
- TestNG is freely available and can be easily installed in the Eclipse IDE using Eclipse Market.
- Upon installation, TestNG would be available as a library within the Eclipse environment.
- Create a new Java Project and configure the build path using TestNG library.
- Create a new TestNG class by expanding the created TestNG project and traverse to its “src” folder. Right click on the “src” package and navigate to New -> Other. Select TestNG class option.
- @Test is one of the annotations provided by TestNG. This annotation lets the program execution to know that method annotated as @Test is a test method. To be able to use different TestNG annotations, we need to import the package “import org.testng.annotations.*”.
- There is no need of main() method while creating test scripts using TestNG.
- We use Assert class while comparing expected and the actual value. Assert class is used to perform various verifications. To be able to use different assertions, we are required to import “import org.testng.Assert”.
- If a test script is composed of more than one test methods, the execution priority and sequence can be set using TestNG annotation “@Test” and by setting a value for the “priority” parameter.
- TestNG has a capability of generating human readable test execution reports automatically. These reports can be viewed in any of the browser and it can also be viewed using Eclipse’s built – in browser support.
Next Tutorial #13: Moving ahead with the upcoming tutorials in the Selenium series, we would concentrate on handling the various types of web elements available on the web pages. Therefore, in the next tutorial, we would concentrate our focus on “dropdowns” and will exercise their handling strategies. We would also discuss about WebDriver’s Select class and its methods to select values in the dropdowns. A remark for the readers: While our next tutorial of the Selenium series is in the processing mode, readers can start creating their own basic WebDriver scripts using TestNG framework. For more advance scripts and concepts, include as many annotations and assertions in your TestNG classes and execute them using TestNG environment. Also analyze the HTML reports generated by TestNG.
|