Tim Malseed
08/03/2021, 2:48 PMandroidx.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
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")
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()
}
}
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.