5

I'm getting the following error when trying to debug androidTests on my device. The only error that appears is the following, and the test hangs forever until I stop it. Test completes ok if I run it, the problem is when I try yo debug it. I have already tried:

  1. Disabling Instant Run
  2. Restarting adb through kill-server and start-server commands.
  3. Restarting android studio.
  4. Invalidating cache and restart.
  5. Different phones
  6. Different computers

This is the error I see in logcat:

W/ting.ventasplu: Current dex file has more than one class in it. Calling RetransformClasses on this class might fail if no transformations are applied to it!
A/ting.ventasplu:nstrumentation.cc:267] Check failed: m == frame.method_ (m=0xb0a66f30, frame.method_=0x6fac48ac) Expected void java.lang.Object.wait(long, int), Found void java.lang.Object.wait(long, int)

This is the InstrumentedTestCode:

@RunWith(AndroidJUnit4::class)
class LoginActivity2InstrumentedTest  {

    lateinit var scenario: ActivityScenario<LoginActivity>

    val viewModel: LoginViewModel = mockk(relaxed = true)

    val app: KoinTestVentasPlusApplication = ApplicationProvider.getApplicationContext()


    @After
    fun cleanup() {
        scenario.close()
    }

    @Test
    @SmallTest
    fun test() {
        app.loadModules(listOf(module { single (override = true) {viewModel} })) {
            scenario = launchActivity()
        }
    }

}

I'm using a custom test runner:

class KoinTestRunner: AndroidJUnitRunner() {
    override fun newApplication(cl: ClassLoader?, className: String?, context: Context?): Application {
        return super.newApplication(
                cl, KoinTestVentasPlusApplication::class.java.name, context
        )
    }
}

And this is the custom application code:

class KoinTestVentasPlusApplication: Application() {       

    override fun onCreate() {
        super.onCreate()   

        startKoin {
            androidLogger()
            androidContext(this@KoinTestVentasPlusApplication)
            modules(emptyList())
        }
    }

    internal fun loadModules(modules: List<Module>, block: () -> Unit) {
        loadKoinModules(modules)
        block()
        unloadKoinModules(modules)
    }
}

This are the dependencies in the gradle file for the mentioned libraries:

androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.1'
androidTestImplementation 'androidx.test:core-ktx:1.2.0'
androidTestImplementation ("org.koin:koin-test:$project.koin"){ exclude group: 'org.mockito' }
androidTestImplementation "io.mockk:mockk-android:1.9.2"

0 Answers0