I've got this really strange problem where it seem...
# androidx
t
I've got this really strange problem where it seems like my InstumentedTests are being run with the Robolectric framework, despite the fact that I'm not (deliberately) using Robolectric. I'm posting here because I am using the
androidx.test.core
APIs, and I suspect that's something to do with it. When I try to run an instrumented test, I get something like:
AndroidJUnitRunner cannot be cast to org.robolectric.android.fakes.RoboMonitoringInstrumentation
My test dependencies look like so:
Copy code
androidTestImplementation("androidx.test:runner:1.4.0")
androidTestImplementation("androidx.test:rules:1.4.0")
androidTestImplementation("androidx.test:core-ktx:1.4.0")
androidTestImplementation("org.hamcrest:hamcrest-library:1.3")
The test:
Copy code
import android.view.View
import androidx.fragment.app.FragmentContainerView
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.launchActivity
import com.simplecityapps.shuttle.ui.MainActivity
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.hamcrest.CoreMatchers.instanceOf
import org.hamcrest.CoreMatchers.notNullValue
import org.hamcrest.MatcherAssert.assertThat
import org.junit.After
import org.junit.Rule
import org.junit.Test

@HiltAndroidTest
class InstrumentedTest {

    @get:Rule
    var hiltRule = HiltAndroidRule(this)

    lateinit var scenario: ActivityScenario<MainActivity>

    @Test
    fun testMainActivityLaunch() {
        scenario = launchActivity<MainActivity>()
        scenario.onActivity {
            val viewById: View = it.findViewById(R.id.onboardingNavHostFragment)
            assertThat(viewById, notNullValue())
            assertThat(viewById, instanceOf(FragmentContainerView::class.java))
        }
    }

    @After
    fun cleanup() {
        scenario.close()
    }
}
And, I am actually using a
CustomTestRunner
in order to have tests work with Hilt. All that seems to be configured OK, and works in another project. But this project seems to be trying to use Robolectric, for some reason.
The only reference I have anywhere to Robolectric, is a dependency on a 3rd party library (ExoPlayer), which does include Robolectric based instrumented tests.
I think this could somehow be confusing the test environment, but I am way out of my depth here.
If anyone has any idea what could be going on here, I'd appreciate some help!
OK, the problem was that I had forked Exoplayer, and I was using Jitpack to build the fork, then depending on the Jitpack build - and all of the artifacts (gradle modules) that come with Exoplayer, instead of just the specific ones I need. One of those modules includes a bunch of robolectric utilities. So, by depending on a module with robolectric utils in it, the test framework was changed to robolectric instead of the android test framework.