Provides the @AutoCleanupTest
and @AutoCleanup
annotations for automatically cleaning up resources after a test run.
dependencies {
implementation("io.github.nillerr:autocleanup-junit5:1.0.0")
}
Annotate a test class with the @AutoCleanupTest
annotation:
@AutoCleanupTest
class UserServiceTests {
// Resources
@AutoCleanup
private val resource = Resource()
// SUT
private val service = UserService(resource)
@Test
fun test() {
// Given
val id = "5"
// When
val result = service.get(id)
// Then
assertEquals(result).isEqualTo(Accounts.default)
}
}
JUnit will now call close()
on the Resource
.