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: Class level @Test annotoation causes "transform()" method invocation multiple times.

See original GitHub issue

TestNG version - 7.5 Java version - 17.0.2 Build tool - Maven, surefire plugin version 3.0.0-M5 IDE -InteliJ

When @Test annotation is set at class level and IAnnotationTransformer interface is implemented, transform() method gets invocated multiple times. I saw the same issue had been reported before and got fixed, but it appears again.

Here is my testng.xml file content attached.

image

The Test Class

@Test
public class SomeTestClass {

    public void someTest() {
        System.out.println("someTest");
    }
}

IAnnotationTransformer implementation class

public class AnnotationTransformer implements IAnnotationTransformer {

    @Override
    public void transform(ITestAnnotation annotation, Class testClass,
                          Constructor testConstructor, Method testMethod) {

        System.out.println(testClass);
    }
}

And here is the output:

image

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
krmahadevancommented, Feb 18, 2022

@David91

For method level @Test annotation transform() method works as expected. It gets invoked once

Ok in that case, a class that has only 1 @Test method should also reflect the same behaviour. If that’s not what is being seen then this for sure would be a defect.

I don’t say only once in any case, but in this case, there is only one @Test annotation on top of the class, so it should be invoked once for that class. Fair expectation. I believe that there’s a defect lurking there somewhere which needs to be taken care of.

Also here is the description of the transform() method from TestNG official doc and it clearly describes when the method should be invoked.

Yes, that’s correct. But it doesn’t call out how many times would the transform be invoked, which is what I was alluding towards 😃

0reactions
David91commented, Feb 18, 2022

Hi @krmahadevan

  1. For method level @Test annotation transform() method works as expected. It gets invoked once
  2. I don’t say only once in any case, but in this case, there is only one @Test annotation on top of the class, so it should be invoked once for that class. Also here is the description of the transform() method from TestNG official doc and it clearly describes when the method should be invoked. image
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. testng.xml.
Read more >
Retry Failed Test in TestNG with IRetryAnalyzer
In the above scenario, test1 and test 2 re-runs 3 times and it fails during each execution. In the Retry class's retry method, ......
Read more >
Test methods, classes and groups - TestNG Docs
In this class, method2() is part of the group "checkin-test", which is defined at the class level, while method1() belongs to both "checkin-test"...
Read more >
TestNG Listeners In Selenium WebDriver With ... - LambdaTest
Class level : In this, you implement listeners for each particular class no ... This method is invoked each time the test method...
Read more >
Documentation - TestNG
5 - Test methods, Test classes and Test groups ... 5.9 - Class level annotations ... invocationCount, The number of times this method...
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