We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
7.5 (also reproducible in previous releases: 7.3.0)
a configuration method annotated with @AfterClass is executed only ONCE after all @Test methods in the class are finished
@AfterClass
@Test
a configuration method annotated with @AfterClass is executed multiple times after all @Test methods in the class are finished
import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class ATest { @BeforeClass public void setup() { System.out.println("BEFORE_" + Thread.currentThread().getName()); } @AfterClass public void tearDown() { System.out.println("AFTER_" + Thread.currentThread().getName()); } @Test public void testa() { System.out.println("testa_" + Thread.currentThread().getName()); } @Test public void testb() { System.out.println("testb_" + Thread.currentThread().getName()); } }
Output:
BEFORE_TestNG-test=tqa-1 testb_TestNG-test=tqa-2 testa_TestNG-test=tqa-1 AFTER_TestNG-test=tqa-1 AFTER_TestNG-test=tqa-2
The text was updated successfully, but these errors were encountered:
It looks like inst is never actually added to the m_classMethodMap.getInvokedAfterClassMethods() https://github.com/cbeust/testng/blob/0ace1d4bdfc4f8c5ccd0849ad4768f4dd08146fd/testng-core/src/main/java/org/testng/internal/invokers/TestMethodWorker.java#L201-L206
inst
m_classMethodMap.getInvokedAfterClassMethods()
Set<Object> instances = invokedAfterClassMethods.computeIfAbsent(testClass, key -> Sets.newHashSet()); Object inst = mi.getInstance(); if (!instances.contains(inst)) { invokeInstances.add(inst); instances.add(inst); }
Sorry, something went wrong.
Streamline AfterClass invocation
d5fa218
Closes testng-team#2726
6b2e466
Closes #2726
Successfully merging a pull request may close this issue.
TestNG Version
7.5 (also reproducible in previous releases: 7.3.0)
Expected behavior
a configuration method annotated with
@AfterClass
is executed only ONCE after all@Test
methods in the class are finishedActual behavior
a configuration method annotated with
@AfterClass
is executed multiple times after all@Test
methods in the class are finishedIs the issue reproducible on runner?
Test case sample
Output:
The text was updated successfully, but these errors were encountered: