What is TestNG?
So
far we had been doing Selenium tests without generating a proper format for the
test results. From this point on, we shall tackle how to make these reports
using a test framework called TestNG.
TestNG
is a Testing framework that overcomes the limitations of
another popular testing framework called JUnit. The "NG" means
"Next Generation." Most Selenium users use this more than Junit because of its advantages. There are so many
features of TestNG, but we will only focus on the most important ones that we
can use in Selenium.
Advantages of TestNG
over JUnit
There
are three major advantages of TestNG over JUnit:
- Annotations are easier to understand
- Test cases can be grouped more easily
- Parallel testing is possible
Annotations
in TestNG are lines of code that can control how the method below them will be
executed. They are always preceded by the @ symbol. A very early and
quick example is the one shown below.
Why do we need TestNG in Selenium?
TestNG
can generate reports based on our Selenium test results.
- WebDriver has no native
mechanism for generating reports.
- TestNG can generate the report in a readable format like the one shown below.
TestNG
simplifies the way the tests are coded
- There is no more need for a static main method in our tests. The sequence of actions is regulated by easy-to-understand annotations that do not require methods to be static.
- Uncaught exceptions are
automatically handled by TestNG without terminating the test prematurely.
These exceptions are reported as failed steps in the report.
Comments
Post a Comment