I'm trying to follow Android Developer Docs to write an Instrumented Unit Test, but, of course, it doesn't work. I am getting the error:
Custom runner class AndroidJUnit4 should have a public constructor with signature AndroidJUnit4(Class testClass)
when ever I run my example test:
package com.devetry.ytp
import android.content.Context
import android.support.test.InstrumentationRegistry
import android.support.test.rule.ActivityTestRule
import android.support.test.runner.AndroidJUnit4
import androidx.test.filters.LargeTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import androidx.test.runner.AndroidJUnitRunner
import org.junit.Assert
import org.junit.Rule
@RunWith(AndroidJUnit4::class)
class ExampleAndroidTest {
/**
* VARIABLES
*/
/**
* LIFE CYCLE
*/
/**
* Example Android Test
*
* An example android test
*/
@Test
fun exampleAndroidTest() {
val context = InstrumentationRegistry.getTargetContext()
Assert.assertEquals("com.devetry.ytp", context.packageName)
}
}
I have tried tried multiple solutions to this specific error I found online, but like most things Android, the solution was either outdated or just simply didn't work. Unfortunately, of all of the solutions, I was unable to even recognize a common theme, thus leaving me stranded.
How can I resolve the error and just get an Instrumented Unit Tests to run?