当前位置: 首页>>代码示例>>Java>>正文


Java ActivityTestRule类代码示例

本文整理汇总了Java中android.support.test.rule.ActivityTestRule的典型用法代码示例。如果您正苦于以下问题:Java ActivityTestRule类的具体用法?Java ActivityTestRule怎么用?Java ActivityTestRule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ActivityTestRule类属于android.support.test.rule包,在下文中一共展示了ActivityTestRule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createRule

import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
ActivityTestRule<FruitActivity>  createRule(){

        return new ActivityTestRule<FruitActivity>(FruitActivity.class) {
            @Override
            protected void beforeActivityLaunched() {

                new SystemLogger().i("FruitViewRotationTestStateBuilder", "beforeActivityLaunched()");

                CustomApp customApp = (CustomApp) InstrumentationRegistry.getTargetContext().getApplicationContext();
                customApp.injectSynchronousObjectGraph();
                //inject our test model
                customApp.injectMockObject(FruitFetcher.class, fruitViewRotationTest.fruitFetcher);
                customApp.registerActivityLifecycleCallbacks(new ProgressBarIdler());

            }

            @Override
            protected void afterActivityFinished() {
                super.afterActivityFinished();

                this.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            }
        };
    }
 
开发者ID:erdo,项目名称:asaf-project,代码行数:25,代码来源:FruitViewRotationTestStateBuilder.java

示例2: testReposActivityFragments

import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
@Test
public void testReposActivityFragments() {
    ActivityTestRule rule = new ActivityTestRule<>(ReposActivity.class, true, false);

    shelfTestUtils.setupBook("book-one", "Preface\n\n* Note");
    shelfTestUtils.setupRepo("file:/");
    shelfTestUtils.setupRepo("dropbox:/orgzly");
    rule.launchActivity(null);

    // List of repos
    fragmentTest(rule, false, withId(R.id.fragment_repos_flipper));

    // Directory repo
    onListItem(1).perform(click());
    fragmentTest(rule, false, withId(R.id.fragment_repo_directory_container));
    pressBack();

    // Dropbox repo
    onListItem(0).perform(click());
    fragmentTest(rule, false, withId(R.id.fragment_repo_dropbox_container));
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:22,代码来源:MiscTest.java

示例3: fragmentTest

import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
private void fragmentTest(ActivityTestRule rule, boolean hasSearchMenuItem, Matcher<View> matcher) {
    onView(matcher).check(matches(isDisplayed()));
    toPortrait(rule);
    onView(matcher).check(matches(isDisplayed()));
    toLandscape(rule);
    onView(matcher).check(matches(isDisplayed()));
    toPortrait(rule);
    onView(matcher).check(matches(isDisplayed()));
    toLandscape(rule);
    onView(matcher).check(matches(isDisplayed()));
    toPortrait(rule);

    if (hasSearchMenuItem) {
        onView(withId(R.id.activity_action_search)).check(matches(isDisplayed()));
    } else {
        onView(withId(R.id.activity_action_search)).check(doesNotExist());
    }
}
 
开发者ID:orgzly,项目名称:orgzly-android,代码行数:19,代码来源:MiscTest.java

示例4: createRule

import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
ActivityTestRule<CounterActivity>  createRule(){

        return new ActivityTestRule<CounterActivity>(CounterActivity.class) {
            @Override
            protected void beforeActivityLaunched() {

                //get hold of the application
                CustomApp customApp = (CustomApp) InstrumentationRegistry.getTargetContext().getApplicationContext();
                customApp.injectSynchronousObjectGraph();

                //inject our mocks so our UI layer will pick them up
                customApp.injectMockObject(CounterWithLambdas.class, mockCounterWithLambdas);
                customApp.injectMockObject(CounterWithProgress.class, mockCounterWithProgress);
            }

        };
    }
 
开发者ID:erdo,项目名称:asaf-project,代码行数:18,代码来源:StateBuilder.java

示例5: createRule

import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
ActivityTestRule<FruitActivity>  createRule(){

        return new ActivityTestRule<FruitActivity>(FruitActivity.class) {
            @Override
            protected void beforeActivityLaunched() {

                //get hold of the application
                CustomApp customApp = (CustomApp) InstrumentationRegistry.getTargetContext().getApplicationContext();
                customApp.injectSynchronousObjectGraph();

                //inject our mocks so our UI layer will pick them up
                customApp.injectMockObject(FruitFetcher.class, mockFruitFetcher);
                customApp.registerActivityLifecycleCallbacks(new ProgressBarIdler());
            }

        };
    }
 
开发者ID:erdo,项目名称:asaf-project,代码行数:18,代码来源:FruitViewTestStateBuilder.java

示例6: createRule

import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
ActivityTestRule<WalletsActivity>  createRule(){

        return new ActivityTestRule<WalletsActivity>(WalletsActivity.class) {
            @Override
            protected void beforeActivityLaunched() {

                //get hold of the application
                CustomApp customApp = (CustomApp) InstrumentationRegistry.getTargetContext().getApplicationContext();
                customApp.injectSynchronousObjectGraph();

                //inject our mocks so our UI layer will pick them up
                customApp.injectMockObject(Wallet.class, mockWallet);
            }

        };
    }
 
开发者ID:erdo,项目名称:asaf-project,代码行数:17,代码来源:StateBuilder.java

示例7: createRule

import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
ActivityTestRule<PlaylistsActivity>  createRule(){

        return new ActivityTestRule<PlaylistsActivity>(PlaylistsActivity.class) {
            @Override
            protected void beforeActivityLaunched() {

                //get hold of the application
                CustomApp customApp = (CustomApp) InstrumentationRegistry.getTargetContext().getApplicationContext();
                customApp.injectSynchronousObjectGraph();

                //inject our mocks so our UI layer will pick them up
                customApp.injectMockObject(PlaylistAdvancedModel.class, mockPlaylistAdvancedModel);
                customApp.injectMockObject(PlaylistSimpleModel.class, mockPlaylistSimpleModel);
            }

        };
    }
 
开发者ID:erdo,项目名称:asaf-project,代码行数:18,代码来源:StateBuilder.java

示例8: testRegisterUserPasswordInvalid

import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
@Test
public void testRegisterUserPasswordInvalid(){
    new ActivityTestRule<>(RegisterScreenActivity.class);

    onView(withId(R.id.nicknameEditText))
            .perform(typeText("testuser"));
    onView(withId(R.id.passwordEditText))
            .perform(typeText("!*"));
    onView(withId(R.id.passwordConfirmEditText))
            .perform(typeText("senha1234"))
            .perform(closeSoftKeyboard());
    onView(withId(R.id.emailEditText))
            .perform(typeText("[email protected]"))
            .perform(closeSoftKeyboard());
    onView(withId(R.id.registerButton))
            .perform(click());
    onView(withId(R.id.passwordEditText)).check(matches(hasErrorText(activity.getString(R.string.passwordValidation))));
}
 
开发者ID:fga-gpp-mds,项目名称:2016.2-MissaoNascente,代码行数:19,代码来源:RegisterAcceptanceTest.java

示例9: testRegisterUserConfirmPasswordInvalid

import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
@Test
public void testRegisterUserConfirmPasswordInvalid(){
    new ActivityTestRule<>(RegisterScreenActivity.class);

    onView(withId(R.id.nicknameEditText))
            .perform(typeText("testuser"));
    onView(withId(R.id.passwordEditText))
            .perform(typeText("senha1234"));
    onView(withId(R.id.passwordConfirmEditText))
            .perform(typeText("!*"))
            .perform(closeSoftKeyboard());
    onView(withId(R.id.emailEditText))
            .perform(typeText("[email protected]"))
            .perform(closeSoftKeyboard());
    onView(withId(R.id.registerButton))
            .perform(click());
    onView(withId(R.id.passwordConfirmEditText)).check(matches(hasErrorText(activity.getString(R.string.passwordConfirmValidation))));
}
 
开发者ID:fga-gpp-mds,项目名称:2016.2-MissaoNascente,代码行数:19,代码来源:RegisterAcceptanceTest.java

示例10: testRegisterUserEmailInvalid

import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
@Test
public void testRegisterUserEmailInvalid(){
    new ActivityTestRule<>(RegisterScreenActivity.class);

    onView(withId(R.id.nicknameEditText))
            .perform(typeText("testuser"));
    onView(withId(R.id.passwordEditText))
            .perform(typeText("senha1234"));
    onView(withId(R.id.passwordConfirmEditText))
            .perform(typeText("senha1234"))
            .perform(closeSoftKeyboard());
    onView(withId(R.id.emailEditText))
            .perform(typeText("[email protected]"))
            .perform(closeSoftKeyboard());
    onView(withId(R.id.registerButton))
            .perform(click());
    onView(withId(R.id.emailEditText)).check(matches(hasErrorText(activity.getString(R.string.invalidEmail))));
}
 
开发者ID:fga-gpp-mds,项目名称:2016.2-MissaoNascente,代码行数:19,代码来源:RegisterAcceptanceTest.java

示例11: recreateActivity

import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
/**
 * Restarts the RecreatedAppCompatActivity and waits for the new activity to be resumed.
 *
 * @return The newly-restarted RecreatedAppCompatActivity
 */
@SuppressWarnings("unchecked") // The type of the recreated activity is guaranteed to be T
public static <T extends RecreatableAppCompatActivity> T recreateActivity(
    ActivityTestRule<? extends RecreatableAppCompatActivity> rule, final T activity)
    throws InterruptedException {
  // Now switch the orientation
  RecreatableAppCompatActivity.resumedLatch = new CountDownLatch(1);
  RecreatableAppCompatActivity.destroyedLatch = new CountDownLatch(1);
  runOnUiThreadRethrow(
      rule,
      new Runnable() {
        @Override
        public void run() {
          activity.recreate();
        }
      });
  assertTrue(RecreatableAppCompatActivity.resumedLatch.await(1, TimeUnit.SECONDS));
  assertTrue(RecreatableAppCompatActivity.destroyedLatch.await(1, TimeUnit.SECONDS));
  T newActivity = (T) RecreatableAppCompatActivity.activity;
  waitForExecution(rule);
  RecreatableAppCompatActivity.clearState();
  return newActivity;
}
 
开发者ID:material-components,项目名称:material-components-android,代码行数:28,代码来源:ActivityUtils.java

示例12: getCurrentActivity

import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
/**
 * Gets an instance of the currently active (displayed) activity.
 * @param activityTestRule test rule
 * @param <T> activity class
 * @return activity instance
 */
public static  <T extends Activity> T getCurrentActivity(@NonNull ActivityTestRule activityTestRule) {
    getInstrumentation().waitForIdleSync();
    final Activity[] activity = new Activity[1];
    try {
        activityTestRule.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                java.util.Collection<Activity> activites = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
                activity[0] = Iterables.getOnlyElement(activites);
            }});
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    }
    //noinspection unchecked
    return (T) activity[0];
}
 
开发者ID:zawadz88,项目名称:material-activity-chooser,代码行数:23,代码来源:ActivityUtils.java

示例13: Disconnect

import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
public static void Disconnect(ActivityTestRule<SnippetListActivity> snippetListActivityTestRule) {
    SnippetListActivity snippetListActivity = snippetListActivityTestRule.launchActivity(null);

    openActionBarOverflowOrOptionsMenu(InstrumentationRegistry.getTargetContext());

    // Espresso can't find menu items by id. We'll use the text property.
    onView(withText(R.string.disconnect_menu_item))
            .perform(click());

    intended(allOf(
            hasComponent(hasShortClassName(".SignInActivity")),
            toPackage("com.microsoft.graph.snippets")
    ));

    snippetListActivity.finish();
}
 
开发者ID:microsoftgraph,项目名称:android-java-snippets-sample,代码行数:17,代码来源:SnippetListActivityTests.java

示例14: getSnippetsIndexes

import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
public static List<Integer> getSnippetsIndexes(ActivityTestRule<SnippetListActivity> snippetListActivityRule) {
    SnippetListActivity snippetListActivity = snippetListActivityRule.launchActivity(null);

    ListAdapter listAdapter = getListAdapter(snippetListActivity);
    int numItems = listAdapter.getCount();

    List<Integer> snippetIndexes = new ArrayList<>();

    // Get the index of items in the adapter that
    // are actual snippets and not categories, which don't have a Url
    for (int i = 0; i < numItems; i++) {
        if(((AbstractSnippet)listAdapter.getItem(i)).getUrl() != null) {
            snippetIndexes.add(i);
        }
    }

    snippetListActivity.finish();

    return snippetIndexes;
}
 
开发者ID:microsoftgraph,项目名称:android-java-snippets-sample,代码行数:21,代码来源:SnippetListActivityTests.java

示例15: rotateOrientation

import android.support.test.rule.ActivityTestRule; //导入依赖的package包/类
public static void rotateOrientation(ActivityTestRule<? extends Activity> testRule) {
    switch (testRule.getActivity().getResources().getConfiguration().orientation) {
        case Configuration.ORIENTATION_LANDSCAPE:
            testRule.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            break;
        default:
            testRule.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
}
 
开发者ID:d4rken,项目名称:ommvplib,代码行数:10,代码来源:TestHelper.java


注:本文中的android.support.test.rule.ActivityTestRule类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。