Created
January 17, 2020 16:28
-
-
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
This file contains 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 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