Download File
Download Project
Settings
Line Wrap
Themes
default
ambiance
bespin
dracula
eclipse
material
mbo
mdn-like
neat
solarized dark
ttcn
zenburn
ChangeTextBehaviorTest.java
/* * Copyright 2016, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.android.testing.espresso.IdlingResourceSample; 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 android.support.test.espresso.Espresso; import android.support.test.espresso.IdlingResource; import android.support.test.filters.LargeTest; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; /** * Same as Espresso's BasicSample, but with an Idling Resource to help with synchronization. */ @RunWith(AndroidJUnit4.class) @LargeTest public class ChangeTextBehaviorTest { private static final String STRING_TO_BE_TYPED = "Espresso"; @Rule public ActivityTestRule
mActivityRule = new ActivityTestRule<>( MainActivity.class); private IdlingResource mIdlingResource; @Before public void registerIdlingResource() { mIdlingResource = mActivityRule.getActivity().getIdlingResource(); // To prove that the test fails, omit this call: Espresso.registerIdlingResources(mIdlingResource); } @Test public void changeText_sameActivity() { // Type text and then press the button. onView(withId(R.id.editTextUserInput)) .perform(typeText(STRING_TO_BE_TYPED), closeSoftKeyboard()); onView(withId(R.id.changeTextBt)).perform(click()); // Check that the text was changed. onView(withId(R.id.textToBeChanged)).check(matches(withText(STRING_TO_BE_TYPED))); } @After public void unregisterIdlingResource() { if (mIdlingResource != null) { Espresso.unregisterIdlingResources(mIdlingResource); } } }