Dictionary meaning of Annotation
Annotating is any action that deliberately interacts with a text to enhance the reader’s understanding of, recall of, and reaction to the text. Sometimes called “close reading,” annotating usually involves highlighting or underlining key pieces of text and making notes in the margins of the text
Annotations in Java
Annotations became available in Java language itself beginning with version 1.5 of the JDK. annotation is a form of syntactic metadata that can be added to Java source code. Classes, methods, variables, parameters and Java packages may be annotated
Annotations in TestNG
TestNG is a Test framework which is used a lot by folks who are writing Selenium Automation Tests. As it allows to group, run and manage the tests better rather than running individual tests using Java main method.
In TestNG, Writing a test is typically a three-step process:
- 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.
How are tests structured in TestNG
Tests in TestNG are structured at 4 levels.
Suite->Tests->TestNG Class->Test Method
Below is a reference from TestNG documentation page (https://testng.org/doc/documentation-main.html)
- 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.
Here is a diagrammatic representation of the hierarchical structure on how the annotations get executed with reference to this structure.
Many of the annotations in TestNG are helping manage and execute things with reference to this pseudo structure.
Below are a quick overview on annotations available in TestNG:-
- @Test:- Represent a method or a class a a test.
- @BeforeSuite:- An annotated method which runs before all tests run in a suite.
- @AfterSuite:- An annotated method which runs after all tests run in a suite.
- @BeforeTest:- An annotated method which will run before any test method belonging to the classes inside the <test> tag is run.
- @AfterTest:- An annotated method which will run after all test method belonging to the classes inside the <test> tag is run.
- @BeforeGroups :- An annotated method which will run before the first method of belonging group run.
- @AfterGroups:- An annotated method which will run after the all method of belonging group run.
- @BeforeClass:- An annotated method which will run before the first test method in the current class is invoked.
- @AfterClass:- An annotated method which will run after the all test methods in the current class is invoked.
- @BeforeMethod:- An annotated method which will run before each test method run.
- @AfterMethod:- An annotated method which will run after each test method run.
- @DataProvider:- Marks a method as supplying data for a test method.
- @Parameters:- It is used to pass parameters to @Test method.
- @Listeners:- Defines listeners on a test class.
- @Factory:- It Marks a method as a factory that returns objects that will be used by TestNG as Test classes.
If you want to read more around these – refer the official documentation
@AgileTA ‘s CPSAT program we cover practical ways of using TestNG for Data Driven testing and much more.
The program is only practical assessment certification program and can be taken in three streams – Java, Python and C#
Just like Selenium the assessment is open too..
Go for it guys