All my tests used to run fine in Travis CI. Since I have upgraded my project to gradle 5.6 some of my unit test failed on Travis CI but succeed locally. They failed with the following message:
java.lang.SecurityException
The test that failed are the one that need to have access to Android Context for small operation. I need to run them under a registration instrumentation but want to keep them as unit test.
I have tried @RunWith(RobolectricTestRunner::class)
and @RunWith(AndroidJUnit4::class)
For example this test that is testing a View Extension that allow me to change the visibility of my view
@Config(sdk = [Build.VERSION_CODES.P])
@RunWith(AndroidJUnit4::class)
class ViewExtUnitTest {
private lateinit var context: Context
@Before
fun setup() {
context = ApplicationProvider.getApplicationContext<WatchMyBackApplication>()
}
@Test
@Throws(Exception::class)
fun whenTrue_viewVisible(){
val view = View(context)
view.visibleOrInvisible(true)
assertThat(view.visibility).isEqualTo(VISIBLE)
}
}
It used to run fine locally and on Travis CI now it failed only on Travis CI
Here's my gradle configuration
buildscript {
ext.kotlin_version = '1.3.60-eap-25'
repositories {
google()
jcenter()
maven { url "https://maven.google.com" }
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0-alpha01'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.4'
classpath 'com.google.gms:google-services:4.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
}
}