Sunday, March 27, 2016

First Espresso Test Setup

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 ""

testCompile 'junit:junit:4.12'

androidTestCompile ''androidTestCompile ''androidTestCompile ''

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: