Reputation: 23535
If I run the SubClass
unit below I expect @AfterAll
to be executed after the test. Yet, the output is just this:
init in super class
init in sub class
test OK
I don't understand why SuperClass#stop()
is not invoked. I understand that @AfterAll
requires a static method or Lifecycle.PER_CLASS
but this is given.
Super class
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.TestInstance
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
open class SuperClass {
init {
println("init in super class")
}
@AfterAll
fun stop(){
println("service stopped")
}
}
Sub class
import org.junit.Test
open class SubClass : SuperClass() {
init {
println("init in sub class")
}
@Test
fun shouldRun() {
println("test OK")
}
}
Upvotes: 3
Views: 2081
Reputation: 23242
Use org.junit.jupiter.api.Test
instead of org.junit.Test
in your JUnit5-tests (check also JUnit 5 User Guide - Annotations).
The following will work as expected:
import org.junit.jupiter.api.Test
open class SubClass : SuperClass() {
init {
println("init in sub class")
}
@Test
fun shouldRun() {
println("test OK")
}
}
Upvotes: 7