Skip to content

Instantly share code, notes, and snippets.

@pedrovgs
Created January 17, 2020 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pedrovgs/49a62fdf451fdbfd80df42bb0c946785 to your computer and use it in GitHub Desktop.
Save pedrovgs/49a62fdf451fdbfd80df42bb0c946785 to your computer and use it in GitHub Desktop.
How to check if I'm running tests with robolectric or instrumentation tests
package com.github.pedrovgs
object TestConfig {
val runningTests by lazy {
isRunningUITests() || isRunningRobolectricTests()
}
private fun isRunningRobolectricTests(): Boolean = checkIfClassIsAvailable("org.robolectric.RobolectricTestRunner")
private fun isRunningUITests(): Boolean = checkIfClassIsAvailable("com.github.pedrovgs.MyAndroidTestRunner")
private fun checkIfClassIsAvailable(s: String): Boolean {
return try {
Class.forName(s)
true
} catch (e: ClassNotFoundException) {
false
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment