implement an Espresso test

This commit is contained in:
tibbi 2015-12-29 12:49:48 +01:00
parent cc856b3d05
commit ca53937aef
3 changed files with 36 additions and 5 deletions

View File

@ -10,6 +10,8 @@ android {
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
@ -25,5 +27,10 @@ dependencies {
compile 'com.jakewharton:butterknife:7.0.1'
testCompile 'junit:junit:4.12'
testCompile "org.robolectric:robolectric:3.0"
testCompile 'org.robolectric:robolectric:3.0'
androidTestCompile 'com.android.support:support-annotations:23.1.1'
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'
}

View File

@ -3,11 +3,8 @@ package calculator.simplemobiletools.com.simple_calculator;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
}

View File

@ -0,0 +1,27 @@
package calculator.simplemobiletools.com.simple_calculator;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
@RunWith(AndroidJUnit4.class)
public class MainActivityTest {
@Rule
public ActivityTestRule<MainActivity> mActivityRule =
new ActivityTestRule<>(MainActivity.class);
@Test
public void addDigitTest() {
onView(withId(R.id.btn_5)).perform(click());
onView(withId(R.id.result)).check(matches(withText("5")));
}
}