Skip to content

Instantly share code, notes, and snippets.

@mandemeskel
Created August 26, 2017 22:41
Show Gist options
  • Save mandemeskel/a772b9f2913361692931e4ce5d4fe0da to your computer and use it in GitHub Desktop.
Save mandemeskel/a772b9f2913361692931e4ce5d4fe0da to your computer and use it in GitHub Desktop.
Refactored test for button that becomes invisible when clicked, using Android Studio 3.
package io.enfant.maggie;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import org.junit.Before;
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.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static org.hamcrest.Matchers.not;
@LargeTest
@RunWith(AndroidJUnit4.class)
public class RecordBtnTests {
@Rule
public ActivityTestRule<MainActivity> mActivityTestRule = new ActivityTestRule<>(MainActivity.class);
@Before
public void runBeforeTest() {
onView(withId(R.id.btnRecord)).perform(click());
}
@Test
public void recordBtnIsInvisible() {
onView(withId(R.id.btnRecord)).check(matches(not(isDisplayed())));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment