@BeforeClass and @AfterClass in superclass ignore groups when running parallel in classes
See original GitHub issueTestNG Version
Edited: 6.14.3
Expected behavior
@BeforeClass
and @AfterClass
in superclass should respect group parameters and be ran before and after classes with those groups.
Actual behavior
On 6.14.3 @BeforeClass
and @AfterClass
run for each class no matter groups they belong to. See example tests and output below. If @BeforeClass
and @AfterClass
are put in each test class instead of superclass then it works fine but it defeats the purpose of having superclass to handle setup and teardown for all test classes. Plus, it adds tons of boilerplate.
On 7.0.0 @BeforeClassand
@AfterClass` run for each class before test methods multiple times. Same happens after test methods.
Is the issue reproductible on runner?
- Shell
- Maven
- Gradle
- Ant
- Eclipse
- IntelliJ
- NetBeans
Test case sample
Class A with group “a”
@Test(groups = ["a"])
class ClassA : BaseTest() {
@Test
fun someTest() {
println("Test in class A with group A ran on ${Thread.currentThread().id} thread")
}
}
Class B with group “b”
@Test(groups = ["b"])
class ClassB : BaseTest() {
@Test
fun someTest() {
println("Test in class B with group B ran on ${Thread.currentThread().id} thread")
}
}
Superclass with @BeforeClass
and @AfterClass
methods for each group.
open class BaseTest {
@BeforeClass(groups = ["a"])
fun beforeClassA() {
println("Ran before class A on ${Thread.currentThread().id} thread")
}
@BeforeClass(groups = ["b"])
fun beforeClassB() {
println("Ran before class B on ${Thread.currentThread().id} thread")
}
@AfterClass(groups = ["a"])
fun afterClassA() {
println("Ran after class A on ${Thread.currentThread().id} thread")
}
@AfterClass(groups = ["b"])
fun afterClassB() {
println("Ran after class B on ${Thread.currentThread().id} thread")
}
}
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="All tests" verbose="1" parallel="classes" thread-count="2" >
<test name="Tests">
<classes>
<class name="test.ClassA" />
<class name="test.ClassB" />
</classes>
</test>
</suite>
Actual Output:
Ran before class A on 14 thread
Ran before class A on 15 thread
Ran before class B on 14 thread
Ran before class B on 15 thread
Test in class A with group A ran on 14 thread
Test in class B with group B ran on 15 thread
Ran after class A on 14 thread
Ran after class A on 15 thread
Ran after class B on 14 thread
Ran after class B on 15 thread
Expected output:
Ran before class A on 14 thread
Ran before class B on 15 thread
Test in class A with group A ran on 14 thread
Test in class B with group B ran on 15 thread
Ran after class A on 14 thread
Ran after class B on 15 thread
Issue Analytics
- State:
- Created 4 years ago
- Comments:19
Top GitHub Comments
You can find the newly opened issue here: #2448
@Proryanator Could you open a new issue? It will be better than this old closed issue 😃