-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Description
I would like to write extension classes implementing BeforeEachCallback, AfterAllCallback and BeforeAllCallback etc. using suspend functions, similar to what is supported when writing these callbacks with annotations. (as of JUnit 6)
suspend fun cleanDatabase() {
// some suspend code
}
// not allowed
internal class DatabaseTestExtension : BeforeEachCallback {
override suspend fun beforeEach(context: ExtensionContext) {
cleanDatabase()
}
}
// allowed
class DatabaseTest {
@BeforeEach
suspend fun beforeEach() {
cleanDatabase()
}
}I would be happy if this was provided via different interfaces (i.e. SuspendBeforeEachCallback, SuspendAfterAllCallback, SuspendBeforeAllCallback, etc. and could be in a different package.
My specific use-case is doing database setup and teardown using r2dbc. I currently work around this with runBlocking which is an acceptable workaround.
internal class DatabaseTestExtension : BeforeEachCallback
override fun beforeEach(context: ExtensionContext) = runBlocking {
cleanDatabase()
}
}Deliverables
- Allow writing extensions that have suspending callback functions.