main.tech.apter.junit.jupiter.robolectric.internal.RobolectricLauncherInterceptor.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of robolectric-extension Show documentation
Show all versions of robolectric-extension Show documentation
This repository aims to bridge the gap between JUnit 5 and Robolectric,
enabling developers to leverage the benefits of both frameworks
for unit testing Android applications. While Robolectric currently lacks
a dedicated JUnit 5 extension, this project proposes a community-driven solution to
achieve seamless integration.
The newest version!
package tech.apter.junit.jupiter.robolectric.internal
import org.junit.platform.launcher.LauncherInterceptor
import tech.apter.junit.jupiter.robolectric.internal.extensions.createLogger
import java.util.concurrent.atomic.AtomicBoolean
@Suppress("LibraryEntitiesShouldNotBePublic")
class RobolectricLauncherInterceptor : LauncherInterceptor {
private inline val logger get() = createLogger()
override fun intercept(invocation: LauncherInterceptor.Invocation): T {
logger.trace { "intercept" }
if (!classLoaderReplaced.getAndSet(true)) {
JUnit5RobolectricTestRunnerHelper.setUp()
}
return invocation.proceed()
}
override fun close() {
logger.trace { "close" }
JUnit5RobolectricTestRunnerHelper.shutdown()
classLoaderReplaced.set(false)
}
private companion object {
@JvmStatic
private val classLoaderReplaced = AtomicBoolean(false)
}
}