WHAT IS TEST NG?
Annotations were formally added to the Java language in JDK 5 and TestNG made the choice to use annotations to annotate test classes.
These are the annotations we using while we are writing the test cases. We place the annotation before the function, according to the annotation the function executes.
Now let’s do some example.
TestNG is a testing framework for the Java programming language inspired from JUnit and NUnit. The design goal of TestNG is to cover a wider range of test categories: unit, functional, end-to-end, integration, etc., with more powerful and easy-to-use functionality.
While we are using TEST NG, we don’t write public static void main. For that we are replacing @TEST, and we are writing the class after that.
ANNOTATION
The traditional way to indicate test methods in JUnit 3 is by prefixing their name with test. This is a very effective method for tagging certain methods in a class as having a special meaning, but the naming doesn’t scale very well (what if we want to add more tags for different frameworks?) and is rather inflexible (what if we want to pass additional parameters to the testing framework?).
Annotations were formally added to the Java language in JDK 5 and TestNG made the choice to use annotations to annotate test classes.
Annotation
|
Description
|
@BeforeSuite
|
The
annotated method will be run only once before all tests in this suite have
run.
|
@AfterSuite
|
The annotated
method will be run only once after all tests in this suite have run.
|
@BeforeClass
|
The
annotated method will be run only once before the first test method in the
current class is invoked.
|
@AfterClass
|
The
annotated method will be run only once after all the test methods in the
current class have been run.
|
@BeforeTest
|
The
annotated method will be run before any test method belonging to the classes
inside the <test> tag is run.
|
@AfterTest
|
The
annotated method will be run after all the test methods belonging to the
classes inside the <test> tag have run.
|
@BeforeGroups
|
The
list of groups that this configuration method will run before. This method is
guaranteed to run shortly before the first test method that belongs to any of
these groups is invoked.
|
@AfterGroups
|
The
list of groups that this configuration method will run after. This method is
guaranteed to run shortly after the last test method that belongs to any of
these groups is invoked.
|
@BeforeMethod
|
The
annotated method will be run before each test method.
|
@AfterMethod
|
The
annotated method will be run after each test method.
|
@DataProvider
|
Marks
a method as supplying data for a test method. The annotated method must
return an Object[ ][ ] where each Object[ ] can be assigned the parameter
list of the test method. The @Test method that wants to receive data from
this Data Provider needs to use a data Provider name equals to the name of
this annotation.
|
@Factory
|
Marks
a method as a factory that returns objects that will be used by TestNG as
Test classes. The method must return Object [ ].
|
@Listeners
|
Defines
listeners on a test class.
|
@Parameters
|
Describes
how to pass parameters to a @Test method.
|
@Test
|
Marks
a class or a method as part of the test.
|
These are the annotations we using while we are writing the test cases. We place the annotation before the function, according to the annotation the function executes.
Now let’s do some example.
No comments:
Post a Comment