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.

Listener's `onAfterClass` is called before `@AfterClass` configuration methods are executed.

See original GitHub issue

TestNG 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

Actual output:

onBeforeClass: dev.pshevche.AfterClassTest
onConfigurationSuccess: setupClass
onTestStart: test1
onTestSuccess: test1
onAfterClass: dev.pshevche.AfterClassTest
onConfigurationSuccess: cleanupClass

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
juherrcommented, Oct 30, 2022

@leonard84 We already added some engine configurations for behavior changes in the past. The current one could use the same mechanism.

0reactions
leonard84commented, Oct 26, 2022

@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?

Read more comments on GitHub >

github_iconTop 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 >

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