The minimal setup for Espresso to get up and running
This will be a very minimal demo of how to setup Espresso testing in your Android Project. First, create a new Android Project to demonstrates how barebones it is.

Add this to your app module build file (the one that is \app\build.gradle )
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:runner:0.4.1'androidTestCompile 'com.android.support.test:rules:0.4.1'androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
your build.gradle should look like this:
Your activity_main.xml should look something like this:
Create a MainActivityTest in your androidTest folder
To run the test right click on MainActivityTest then Run 'MainActivityTest'

Your test should pass like this:

To test if your test is indeed correctly setup change the text in the TextView to something else. You should receive a failed test like this:

If at this point your test still passes you shouldn't be happy that it passed. Something's wrong with your test.
No comments:
Post a Comment