I'm running a espresso uiautomator test which runs well when using the green run > button on android studio. (image below)
Yet ./gradlew connectedAndroidTest is giving an error:
No Koin Context configured. Please use startKoin or koinApplication DSL
Why does it run through android studio but not on gradle? And how do I fix it?
@LargeTest
@RunWith(AndroidJUnit4::class)
class MainActivityTest {
@Rule
@JvmField
var mActivityTestRule = ActivityTestRule(MainActivity::class.java)
lateinit var context: Context
lateinit var mainActivity: MainActivity
lateinit var idlingResource: MainActivityIdlingResource
private lateinit var myDevice: UiDevice
private val sleepMedium: Long = 1000
@Before
fun setup() {
context = InstrumentationRegistry.getInstrumentation().targetContext
mainActivity = mActivityTestRule.activity
myDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
idlingResource = MainActivityIdlingResource(
mActivityTestRule.activity.recyclerList,
mActivityTestRule.activity.javaClass.simpleName
)
IdlingRegistry.getInstance().register(idlingResource)
}
@After
fun teardown() {
IdlingRegistry.getInstance().unregister(idlingResource)
}
/**
* check swipe
*/
@Test
fun testSwipe() {
myDevice.findObject(UiSelector().descriptionContains("recyclerList"))
.swipeUp(2) //to scroll up
waitTime(sleepMedium)
myDevice.findObject(UiSelector().descriptionContains("recyclerList"))
.swipeDown(2) //to scroll down
waitTime(sleepMedium)
}

You have to use
startKoinand set the context by usingandroidContextfor your ClassMainActivityTestAlso, try checking that have you registered the Application class in manifest file
If this also doesn't work, Upgrade. The Start context has been fixed to be more consistent.