Reputation: 305
In superclass, the method annotated with @BeforeClass
seems not to be executed
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
open class TestBase {
var status: Boolean = false
@BeforeAll
open fun setStatus() {
status = true
}
}
class MyAppTest : TestBase() {
@Test
fun testStatus() {
assertTrue(status) //fails
}
}
Is this the desirable behaviour or am I doing something wrong?
Upvotes: 4
Views: 5008
Reputation: 39843
The documentation explicitly states:
@BeforeAll
methods are inherited from superclasses as long as they are not hidden or overridden. Furthermore,@BeforeAll
methods from superclasses will be executed before@BeforeAll
methods in subclasses.
So this would not be the desired behavior. But since setStatus()
is open, you have to be careful not to override it.
Upvotes: 6