question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IAnnotationTransformer doesn't run when specified as an @Listeners

See original GitHub issue

IAnnotationTransformer only works when specified in the suite xml file with <listeners>. I would like it to also run the transformer when specified in the @Listener annotation

Example:

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import org.testng.IAnnotationTransformer;
import org.testng.annotations.ITestAnnotation;

public class TransformerImpl implements IAnnotationTransformer {

    @Override
    public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
        System.out.println("Transform Annotation");
    }
}
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

@Listeners({ TransformerImpl.class })
public class AnnotationTest {

    @Test
    public void run() {
        System.out.println("run");
    }
}

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:7

github_iconTop GitHub Comments

7reactions
rkonkulcommented, Apr 9, 2015

From the documentation: (http://testng.org/doc/documentation-main.html)

The @Listeners annotation can contain any class that extends org.testng.ITestNGListener except IAnnotationTransformer and IAnnotationTransformer2. The reason is that these listeners need to be known very early in the process so that TestNG can use them to rewrite your annotations, therefore you need to specify these listeners in your testng.xml file. 
0reactions
krmahadevancommented, Oct 21, 2020

@ChenaLee - Not true to the best of my knowledge. I think the javadocs makes this explicit.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - overridden transform method of IAnnotationTransformer ...
I used testng.xml to use listeners but invocation count is not changing ... Method; public class Listeners implements IAnnotationTransformer ...
Read more >
Exploring TestNG Listeners for controlled Execution - LinkedIn
IAnnotationTransformer works, only when specified in testng suite xml file and will not work when specified in the @Listeners annotation. The @ ...
Read more >
Use IAnnotationTransformer to disable testcases
I have written an AnnotationTransformer to disable certain tests. import java.lang.reflect.Constructor; import java.lang.reflect.Method; import org.
Read more >
Test methods, classes and groups - TestNG Docs
Groups are specified in your testng.xml file and can be found either under ... your test methods are run in a certain order...
Read more >
TestNG (TestNG 6.8.17 API) - Javadoc.io
void, setUseDefaultListeners(boolean useDefaultListeners) If this method is passed true before run(), the default listeners will not be used.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found