Skip to content

Instantly share code, notes, and snippets.

@up1
Last active August 29, 2015 14:17
Show Gist options
  • Save up1/41ef122435874a7ec872 to your computer and use it in GitHub Desktop.
Save up1/41ef122435874a7ec872 to your computer and use it in GitHub Desktop.
Demo espresso
dependencies {
...
compile 'com.android.support:support-annotations:21.0.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
}
android {
....
defaultConfig {
....
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
}
onView(withId(R.id.myText)).check(matches(withText(expected)));
onView(withId(R.id.convert)).perform(click());
package com.example;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.LargeTest;
import com.example.somkiat.calculate.MyActivity;
import com.example.somkiat.calculate.R;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.typeText;
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;
@LargeTest
public class MyGradeCalculate extends ActivityInstrumentationTestCase2<MyActivity> {
public MyGradeCalculate() {
super(MyActivity.class);
}
@Override
public void setUp() throws Exception {
super.setUp();
getActivity();
}
public void testShowGradeDWhenScoreIs50() {
onView(withId(R.id.score)).perform(typeText(String.valueOf(50)));
onView(withId(R.id.convert)).perform(click());
onView(withId(R.id.result)).check(matches(withText("Your grade = D")));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment