Listener's `onAfterClass` is called before `@AfterClass` configuration methods are executed.
See original GitHub issueTestNG Version
7.6.1 and older
Expected behavior
I would expect that listener’s onAfterClass
method is executed after onConfiguration*
methods for all methods annotated with @AfterClass
are called. Similarly to how onBeforeClass
is called before the first method annotated with @BeforeClass
is called.
Or at least that the ordering is consistent for both types of configuration methods.
Actual behavior
onBeforeClass
is called before configuration methods annotated w/@BeforeClass
are executed.onAfterClass
is called before configuration methods annotated w/@AfterClass
are executed.
Is the issue reproducible on runner?
Issue is reproducible both on Gradle and Maven runners, did not check anything else. Here is a small Gradle project with listener and test case implementations that illustrates the problem: https://github.com/pshevche/testng-after-class-order-reproducer
Test case sample
- Test case: https://github.com/pshevche/testng-after-class-order-reproducer/blob/main/lib/src/test/java/dev/pshevche/AfterClassTest.java
- Listener implementation: https://github.com/pshevche/testng-after-class-order-reproducer/blob/main/lib/src/main/java/dev/pshevche/LoggingListener.java
Actual output:
onBeforeClass: dev.pshevche.AfterClassTest
onConfigurationSuccess: setupClass
onTestStart: test1
onTestSuccess: test1
onAfterClass: dev.pshevche.AfterClassTest
onConfigurationSuccess: cleanupClass
Issue Analytics
- State:
- Created a year ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
TestNG Annotations and Listeners - Software Testing Help
It is a listener that monitors the beginning and end of a TestNG run. It has two methods i.e. onExecutionStart() and onExecutionFinish().
Read more >How to make testng listeners runs before the @AfterClass ...
Problem I'm facing - Listener is generating the report only @AfterClass method gets executed. Is there a way to make the listener generate...
Read more >TestNG Annotations - Javatpoint
The @AfterClass annotated method will be invoked after the execution of all the test methods of the current class. @BeforeMethod, The @BeforeMethod annotated ......
Read more >Documentation - TestNG
@BeforeClass: The annotated method will be run before the first test method in the current class is invoked. @AfterClass: The annotated method will...
Read more >TestNG Annotations - Benefits, Hierarchy & TestNG Test ...
@AfterTest - The @AfterTest method in TestNG executes after the execution of all the test methods that are inside that folder. @BeforeClass - ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@leonard84 We already added some engine configurations for behavior changes in the past. The current one could use the same mechanism.
@cbeust if you are really worried that a fix would break existing users, would you consider introducing a new listener interface, that has the “correct” behavior, or introduce a new default method
onAfterClassAfterMethods
that gets called at the correct time?