1.2. Example of IAnnotationTransformer
is a TestNG allows you to do using its annotation transformation framework. In general annotations are static in nature by design, so any change in the values require recompilation of source files. Since TestNG relies heavily on annotations, it would be nice if one can override its behavior at runtime.
There are four different ways to achieve this
1.2.1. Example of @Test annotation transformer
1.2.2. Example of @DataProvider annotation transformer
1.2.3. Example of @Factory annotation transformer
1.2.4. Example of Configuration annotation transformer
===========================================================================
1.2.1. Example of @Test annotation transformer
Representation :
In the below example, we configure the annotation.
is our test class. It contains test methods , and . Methods and accept a string parameter but we haven’t provided any . The will be set on-the-fly in the annotation transformer, based on the method, and also by using will disable the test case.
TestAnnotationTransformerExample;
1.2.2. Example of @DataProvider annotation transformer
If we want to modify any TestNG annotation besides then we can make use of @Dataprovider annotation transformer. In this example, based on the , we decide whether it should be used in parallel. If the returns a "getDP3", we run it in parallel.
1.2.3. Example of @Factory annotation transformer
In this example, we transform a factory annotation.
is a test class which depends on annotation for its creation. We will modify the annotation dynamically to set its source to a .
1.2.4. Example of Configuration annotation transformer
In this example, we will alter the configuration based annotations like , etc.
is the test class. It contains some configuration methods with a attribute.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.