Raghunandan J
Raghunandan J

Reputation: 594

Disable particular tests through Annotation Transformer : TestNG

I have a huge project with numerous test cases. Some test cases are suppose to work on only particular environments and some are not. So I'm trying to skip or disable tests which don't belong to that environment.

I'm using Annotation Transformers to override @Test 's behaviour.

Here is my Transformer code in

package com.raghu.listener

public class SkipTestsTransformer implements IAnnotationTransformer {
    public void transform(ITestAnnotation annotation, Class testClass,
            Constructor testConstructor, java.lang.reflect.Method testMethod){

//          I intend to do this later
//          if(someCondition){
//              // Do something.
//          }
                System.out.println("Inside Transform");
    }
}

As of now I'm just trying to print.

I have many packages and classes on which I have to impose this Transformer.

How and Where should I initiate this class?

Please suggest any better methods for doing the same.

Thanks in advance

Upvotes: 1

Views: 2396

Answers (1)

niharika_neo
niharika_neo

Reputation: 8531

IAnnotationTransformer is a listener. You do not need to instantiate it, testng would do it for you. You can specify a listener in any of the listed ways here., either through your xmls or through service loaders, depending upon your test environment.

If you do not have groups marked in your testcases, then I think this is the way to go by setting the enabled attribute to false. There is another way to skip a test in IInvokedMethodListener, but I do not see any benefit of one over the other.

Upvotes: 1

Related Questions