So I'm trying to test my activity following googles instructions here: https://developer.android.com/guide/components/activities/testing
But the code launchActivity<MyActivity>()
does not work. Do I need to define launchActivity as a rule or is there a library I need to import in gradle?
These are the imports I already have
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
You will useAndroid studio to create an Android application under a package com. tutorialspoint.
unit tests can be written under test java package, and instrumental tests can be written under androidTest package. You can then access UI widgets using Espresso ViewMatchers and then you can apply actions on them using ViewActions . Check documentation for further help. Show activity on this post.
JUnit is a “Unit Testing” framework for Java Applications which is already included by default in android studio. It is an automation framework for Unit as well as UI Testing. It contains annotations such as @Test, @Before, @After, etc.
You need to import following dependency into your gradle.
androidTestImplementation 'androidx.test:core-ktx:1.1.0'
Moreover, also add this in gradle file to avoid compile time error after adding launchActivity
method in your test code.
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
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