I'm working on automation test using Espresso.
The folder in which Instrumentation test classes can be written is missing
Screenshot of the project
I tried by adding
android{
sourceSets{
main { java.srcDirs = ['src/main/java'] }
test { java.srcDirs = ['src/test/java'] }
androidTest { java.srcDirs = ['src/androidTest/java'] }
}
}
inside build.gradle but didn't work.
Tried to generate by using other solutions provided in this question still doesn't work
So to fix “SDK tools directory missing” in android studio, try the following methods The Cause for this error -SDK tools package might not be installed. Quick fix: Go to the Tools –> SDK manager –> SDK tools. Deselect Hide obsolete packages option on the right bottom and further install Android SDK Tools (obsolete).
You have installed Android Studio and now looking for Android SDK and other things. AppData folder should be inside your user directory. You are worried that you are not able to see AppData folder inside your user directory. Don't worry, it is hidden. You can easily make it visible.
Clicking on the tab should open a pane with your modules and build variants for those modules. Above the modules is a Test Artifact dropdown which you should change to Android Instrumentation Tests. Show activity on this post.
Quick fix: Uninstall Android SDK (default location C:\Users\..\AppData\Local\Android\Sdk ) and install it again. This time affirms the minimum required storage space at your place of download. After execution check, if tools folder is now added in SDK directory.
The quickest way is to auto-generate the folder and record an espresso test. On the top menu bar of Android Studio, click on "Run" then -> "Record Espresso Test".
This will start your emulator and also open up the recorder dialog. Then just perform a few actions on your emulator and then click "ok" on the recorder dialog. Android Studio will generate the test as well as the missing folder. You will basically have a template test setup for you to start editing as you wish.
Create your androidTest folder like any other folder. Put it under app/src. You can event create this folder outside Android Studio if you want.
Put the right dependencies in your build.gradle file. Something like this:
testImplementation 'junit:junit:4.12'
testImplementation 'androidx.arch.core:core-testing:2.0.1'
androidTestImplementation 'androidx.test:rules:1.1.1'
androidTestImplementation 'androidx.test:runner:1.1.2-alpha02'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha02'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.1'
Put the testInstrumentationRunner setting in your build.gradle file:
android {
defaultConfig {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
}
And in your test class, which you will save under app/src/androidTest/[your namespace here], will look something like this:
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.assertEquals;
@RunWith(AndroidJUnit4.class)
public class PrincipalTest {
@Test
public void testAppContext() {
Context context = InstrumentationRegistry.getTargetContext();
assertEquals("my.package.name", context.getPackageName());
}
}
Right click to your src folder and add a new directory then click androidTest\java
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