Skip to content

Commit

Permalink
Remove use of android.test APIs from testapp tests
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 224247299
  • Loading branch information
brettchabot authored and copybara-androidxtest committed Dec 6, 2018
1 parent 235ccfb commit 9991add
Show file tree
Hide file tree
Showing 24 changed files with 345 additions and 380 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,32 @@
import static androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckResultUtils.matchesViews;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import android.os.Build;
import android.test.ActivityInstrumentationTestCase2;
import android.view.View;
import android.widget.LinearLayout.LayoutParams;
import androidx.test.core.app.ActivityScenario;
import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.contrib.AccessibilityChecks;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import com.google.android.apps.common.testing.accessibility.framework.integrations.AccessibilityViewCheckException;
import org.hamcrest.Matcher;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Demonstrates use of {@link AccessibilityChecks}.
*/
/** Demonstrates use of {@link AccessibilityChecks}. */
@RunWith(AndroidJUnit4.class)
@LargeTest
public class AccessibilityChecksTest extends
ActivityInstrumentationTestCase2<LargeViewActivity> {

public AccessibilityChecksTest() {
super(LargeViewActivity.class);
}
public class AccessibilityChecksTest {

@Override
@Before
public void setUp() throws Exception {
super.setUp();
getActivity();
ActivityScenario.launch(LargeViewActivity.class);

// ViewAction to set the height, width to be too small, which will cause an a11y exception
onView(withId(R.id.large_view)).perform(new ViewAction() {
Expand All @@ -71,9 +70,10 @@ public void perform(UiController uiController, View view) {
}

/**
* Demonstrates how to run Accessibility Checks by default on all actions contained in
* {@link ViewActions}
* Demonstrates how to run Accessibility Checks by default on all actions contained in {@link
* ViewActions}
*/
@Test
public void testRunAccessibilityChecks_usingPressMenuKey() {
// will not run accessibility checks (off by default), so no error will be thrown
onView(withId(R.id.large_view)).perform(pressMenuKey());
Expand All @@ -92,6 +92,7 @@ public void testRunAccessibilityChecks_usingPressMenuKey() {
* Demonstrates how to run global assertions, and in particular Accessibility Checks, before
* custom actions.
*/
@Test
public void testRunAccessibilityChecks_usingCustomAction() {
// could be any custom action, this one does nothing
ViewAction customAction = new ViewAction() {
Expand Down Expand Up @@ -128,6 +129,7 @@ public void perform(UiController uiController, View view) {
* Demonstrates how to run Accessibility Checks with a custom configuration, in this case with a
* suppressing result matcher to suppress the error.
*/
@Test
public void testRunAccessibilityChecks_usingCustomConfiguration() {
AccessibilityChecks.enable()
// set the suppressing result matcher, which could be used to suppress known bugs
Expand All @@ -144,6 +146,7 @@ public void testRunAccessibilityChecks_usingCustomConfiguration() {
}
}

@Test
public void testEnableAccessibilityChecksTwice_throwsIllegalStateException() {
AccessibilityChecks.enable();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,25 @@
import static androidx.test.espresso.action.ViewActions.typeText;
import static androidx.test.espresso.matcher.ViewMatchers.withId;

import android.test.ActivityInstrumentationTestCase2;
import androidx.test.core.app.ActivityScenario;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Demonstrates Espresso with action bar and app compat searchview widget
*/
/** Demonstrates Espresso with action bar and app compat searchview widget */
@RunWith(AndroidJUnit4.class)
@LargeTest
public class ActionBarSearchActivityTest extends
ActivityInstrumentationTestCase2<ActionBarSearchActivity> {

@SuppressWarnings("deprecation")
public ActionBarSearchActivityTest() {
// This constructor was deprecated - but we want to support lower API levels.
super("androidx.test.ui.app", ActionBarSearchActivity.class);
}
public class ActionBarSearchActivityTest {

@Override
@Before
public void setUp() throws Exception {
super.setUp();
// Espresso will not launch our activity for us, we must launch it via getActivity().
getActivity();
// Espresso will not launch our activity for us, we must launch it via ActivityScenario.launch.
ActivityScenario.launch(ActionBarSearchActivity.class);
}

@Test
@SuppressWarnings("unchecked")
public void testAppCompatSearchViewFromActionBar() {
onView(withId(R.id.menu_search))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package androidx.test.ui.app;

import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
import static androidx.test.espresso.Espresso.openContextualActionModeOverflowMenu;
Expand All @@ -24,30 +25,29 @@
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;

import android.test.ActivityInstrumentationTestCase2;
import androidx.test.core.app.ActivityScenario;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Demonstrates Espresso with action bar and contextual action mode.
* {@link openActionBarOverflowOrOptionsMenu()} opens the overflow menu from an action bar.
* {@link openContextualActionModeOverflowMenu()} opens the overflow menu from an contextual action
* mode.
* Demonstrates Espresso with action bar and contextual action mode. {@link
* openActionBarOverflowOrOptionsMenu()} opens the overflow menu from an action bar. {@link
* openContextualActionModeOverflowMenu()} opens the overflow menu from an contextual action mode.
*/
@RunWith(AndroidJUnit4.class)
@LargeTest
public class ActionBarTest extends ActivityInstrumentationTestCase2<ActionBarTestActivity> {
@SuppressWarnings("deprecation")
public ActionBarTest() {
// This constructor was deprecated - but we want to support lower API levels.
super("androidx.test.ui.app", ActionBarTestActivity.class);
}
public class ActionBarTest {

@Override
@Before
public void setUp() throws Exception {
super.setUp();
// Espresso will not launch our activity for us, we must launch it via getActivity().
getActivity();
// Espresso will not launch our activity for us, we must launch it via ActivityScenario.launch.
ActivityScenario.launch(ActionBarTestActivity.class);
}

@Test
@SuppressWarnings("unchecked")
public void testClickActionBarItem() {
onView(withId(R.id.hide_contextual_action_bar))
Expand All @@ -60,6 +60,7 @@ public void testClickActionBarItem() {
.check(matches(withText("Save")));
}

@Test
@SuppressWarnings("unchecked")
public void testClickActionModeItem() {
onView(withId(R.id.show_contextual_action_bar))
Expand All @@ -72,14 +73,14 @@ public void testClickActionModeItem() {
.check(matches(withText("Lock")));
}


@Test
@SuppressWarnings("unchecked")
public void testActionBarOverflow() {
onView(withId(R.id.hide_contextual_action_bar))
.perform(click());

// Open the overflow menu from action bar
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
openActionBarOverflowOrOptionsMenu(getApplicationContext());

onView(withText("World"))
.perform(click());
Expand All @@ -88,6 +89,7 @@ public void testActionBarOverflow() {
.check(matches(withText("World")));
}

@Test
@SuppressWarnings("unchecked")
public void testActionModeOverflow() {
onView(withId(R.id.show_contextual_action_bar))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,33 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;

import android.test.ActivityInstrumentationTestCase2;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import androidx.test.core.app.ActivityScenario;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Demonstrates the usage of {@link
* androidx.test.espresso.Espresso#onData(org.hamcrest.Matcher)} to match data within list
* views.
* Demonstrates the usage of {@link androidx.test.espresso.Espresso#onData(org.hamcrest.Matcher)} to
* match data within list views.
*/
@RunWith(AndroidJUnit4.class)
@LargeTest
public class AdapterViewTest extends ActivityInstrumentationTestCase2<LongListActivity> {
public class AdapterViewTest {

@SuppressWarnings("deprecation")
public AdapterViewTest() {
// This constructor was deprecated - but we want to support lower API levels.
super("androidx.test.ui.app", LongListActivity.class);
}

@Override
@Before
public void setUp() throws Exception {
super.setUp();
getActivity();
ActivityScenario.launch(LongListActivity.class);
}

@Test
public void testClickOnItem50() {
// The text view "item: 50" may not exist if we haven't scrolled to it.
// By using onData api we tell Espresso to look into the Adapter for an item matching
Expand All @@ -70,6 +68,7 @@ public void testClickOnItem50() {
.check(matches(withText("50")));
}

@Test
public void testClickOnSpecificChildOfRow60() {
onData(withItemContent("item: 60"))
.onChildView(withId(R.id.item_size)) // resource id of second column from xml layout
Expand All @@ -82,6 +81,7 @@ public void testClickOnSpecificChildOfRow60() {
.check(matches(withText("2")));
}

@Test
public void testClickOnFirstAndFifthItemOfLength8() {
onData(is(withItemSize(8)))
.atPosition(0)
Expand All @@ -98,6 +98,7 @@ public void testClickOnFirstAndFifthItemOfLength8() {
.check(matches(withText("14")));
}

@Test
@SuppressWarnings("unchecked")
public void testClickFooter() {
onData(isFooter())
Expand All @@ -107,8 +108,9 @@ public void testClickFooter() {
.check(matches(withText("100")));
}

@Test
@SuppressWarnings("unchecked")
public void testDataItemNotInAdapter(){
public void testDataItemNotInAdapter() {
onView(withId(R.id.list))
.check(matches(not(withAdaptedData(withItemContent("item: 168")))));
}
Expand Down
Loading

0 comments on commit 9991add

Please sign in to comment.