Created
February 19, 2019 13:56
-
-
Save kingargyle/e73e861a4d3d22e9f657e5a6c53f99c0 to your computer and use it in GitHub Desktop.
A bare bones RobolectrictTestRunner that only starts up a sandbox and does not attempt to load any resources. This is good for non-ui tests where you still need portions of the android library but not any of the resources. Reduces robolectric startup time to 2 seconds. This comes from the following google group post: https://groups.google.com/fo…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package us.nineworlds.serenity.testrunner | |
import org.junit.runners.model.FrameworkMethod | |
import org.junit.runners.model.InitializationError | |
import org.robolectric.RobolectricTestRunner | |
import org.robolectric.annotation.Config | |
import org.robolectric.internal.SandboxTestRunner | |
import org.robolectric.internal.bytecode.Sandbox | |
import java.lang.reflect.Method | |
class PlainAndroidRunner @Throws(InitializationError::class) | |
constructor(testClass: Class<*>) : RobolectricTestRunner(testClass) { | |
override fun afterTest(method: FrameworkMethod, bootstrappedMethod: Method?) {} | |
@Throws(Throwable::class) | |
override fun beforeTest(sandbox: Sandbox, method: FrameworkMethod, bootstrappedMethod: Method?) { | |
} | |
override fun getHelperTestRunner(bootstrappedTestClass: Class<*>): org.robolectric.internal.SandboxTestRunner.HelperTestRunner { | |
try { | |
return SandboxTestRunner.HelperTestRunner(bootstrappedTestClass) | |
} catch (initializationError: InitializationError) { | |
throw RuntimeException(initializationError) | |
} | |
} | |
override fun buildGlobalConfig(): Config { | |
return Config.Builder().setManifest(Config.NONE).build() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note this is under an MIT license.