Introduction to TestNG
TestNG is a testing framework designed to simplify a
broad range of testing needs, from unit testing (testing a class in isolation
of the others) to integration testing (testing entire systems made of several
classes, several packages and even several external frameworks, such as
application servers).
Write the business logic of your test and insert
TestNG annotations in your code.
Add the information about your test (e.g. the class
name, the groups you wish to run, etc...) in a testng.xml file or in build.xml.
Run TestNG.
You can find a quick example on the Welcome page.
A suite is represented by one XML file. It can
contain one or more tests and is defined by the <suite> tag.
A test is represented by <test> and can
contain one or more TestNG classes.
A TestNG class is a Java class that contains at
least one TestNG annotation. It is represented by the <class> tag and can
contain one or more test methods.
A test method is a Java method annotated by @Test in
your source.
A list of all the annotations with a brief
explanation. This will give you an idea of the various functionalities offered
by TestNG but you will probably want to consult the section dedicated to each
of these annotations to learn the details.
A description of the testng.xml file, its syntax and
what you can specify in it.
A detailed list of the various features and how to
use them with a combination of annotations and testng.xml.
In Selenium WebDriver training tutorial we have seen
how to run Selenium scripts using JUnit framework. Until now we have execute
selenium tests but we have not generated reports in JUnit. In this Selenium
training article series we are introducing powerful new testing framework
called TestNG. The TestNG framework means Next Generation testing framework, so
we are seeing what all next generation features available in TestNG.
What
is TestNG?
TestNG is testing framework inspired from most
popular JUnit framework used for the Java programming language. The TestNG
framework is introduced to overcome the limitations of JUnit framework. Most of
the automation users are using this framework because of its advantages &
more supported features. Until we have executed selenium test script but not
even generated test reports. So using this TestNG framework we will learn how
to generate test reports.
TestNG supports many powerful features & it is
easy to use. Let’s see what all new features are supported in new testing
framework:
Supports dependent methods testing.
Test configuration flexible.
Supports powerful execution model.
Embeds BeanShell for further flexibility.
TestNG has a more elegant way of handling
parameterized tests with the data-provider concept.
For the same test class TestNG support for multiple
instances.
Extendibility of using different Tools and plug-ins
like Eclipse, Maven, IDEA etc.
Default JDK functions for runtime and logging (no
dependencies).
TestNG supports annotations which are very helpful
to guide test case executions. Similarly in JUnit, the TestNG annotations are
always preceded by the ‘@’ symbol. It permit you do parallel execution of test
cases & we can also skip the test cases effortlessly while executing test
cases.
TestNG is specially designed to cover all types
testing categories like Unit, Functional testing, Integration testing,
End-to-end etc. Using TestNG framework allows us to generate test reports in
both HTML and XML formats. Using ANT with TestNG, we can generate primitive
Testng reports as well.
In TestNG Annotations are easy to understand over
JUnit.
In TestNG there is no constraint like you have to
declare @BeforeClass and @AfterClass, which is present in JUnit.
As method name constraint is present in JUnit, such
method name constraint is not present in TestNG and you can specify any test
method names.
In TestNG enable you to grouping of test cases
easily which is not possible in JUnit.
TestNG supports following three 3 additional
setUp/tearDown level:
@Before/AfterSuite, @Before/AfterTest and
@Before/AfterGroup.
TestNG do not require extend any class.
TestNG allows us to define the dependent test cases
each test case is independent to other test case.
TestNG allows us to execute of test cases based on
group. Let’s take a scenario where we have created two set of groups
“Regression” & “Sanity”. If we want to execute the test cases under Sanity
group then it is possible in TestNG framework.
Parallel execution of Selenium test cases is
possible in TestNG.
No comments:
Post a Comment