简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM