提交 0a06e54c 创建 作者: Greyson Parrelli's avatar Greyson Parrelli

Added a functional test.

上级 20c1caae
...@@ -2,11 +2,20 @@ package com.greysonparrelli.gitlabciandroid; ...@@ -2,11 +2,20 @@ package com.greysonparrelli.gitlabciandroid;
import android.content.Context; import android.content.Context;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4; import android.support.test.runner.AndroidJUnit4;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; 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.action.ViewActions.closeSoftKeyboard;
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;
import static org.junit.Assert.*; import static org.junit.Assert.*;
/** /**
...@@ -15,12 +24,23 @@ import static org.junit.Assert.*; ...@@ -15,12 +24,23 @@ import static org.junit.Assert.*;
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest { public class AddingTest {
@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(MainActivity.class);
@Test @Test
public void useAppContext() throws Exception { public void addNumbers() throws Exception {
// Context of the app under test. // Enter numbers to be added
Context appContext = InstrumentationRegistry.getTargetContext(); onView(withId(R.id.num1))
.perform(typeText("1"), closeSoftKeyboard());
onView(withId(R.id.num2))
.perform(typeText("2"), closeSoftKeyboard());
// Click the calculate button
onView(withId(R.id.calc_button)).perform(click());
assertEquals("com.greysonparrelli.gitlabciandroid", appContext.getPackageName()); onView(withId(R.id.sum))
.check(matches(withText("3")));
} }
} }
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论