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 startKoin
and set the context by using androidContext
for your Class MainActivityTest
startKoin {
androidLogger()
// declare used Android context
androidContext(this@MainActivityTest)
// declare modules
modules(listOf(module1, module2, ...))
}
Also, try checking that have you registered the Application class in manifest file
<application
android:name=".MainActivityTest"
If this also doesn't work, Upgrade. The Start context has been fixed to be more consistent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With