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


Java InstrumentationRegistry.getInstrumentation方法代码示例

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


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

示例1: testA

import android.support.test.InstrumentationRegistry; //导入方法依赖的package包/类
/**
 * 测试CollapsingToolbarLayout
 * 被测Demo下载地址:https://github.com/alidili/DesignSupportDemo
 *
 * @throws UiObjectNotFoundException
 */
public void testA() throws UiObjectNotFoundException {
    // 获取设备对象
    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    UiDevice uiDevice = UiDevice.getInstance(instrumentation);
    // 获取上下文
    Context context = instrumentation.getContext();

    // 启动测试App
    Intent intent = context.getPackageManager().getLaunchIntentForPackage("com.yang.designsupportdemo");
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    context.startActivity(intent);

    // 打开CollapsingToolbarLayout
    String resourceId = "com.yang.designsupportdemo:id/CollapsingToolbarLayout";
    UiObject collapsingToolbarLayout = uiDevice.findObject(new UiSelector().resourceId(resourceId));
    collapsingToolbarLayout.click();

    for (int i = 0; i < 5; i++) {
        // 向上移动
        uiDevice.swipe(uiDevice.getDisplayHeight() / 2, uiDevice.getDisplayHeight(),
                uiDevice.getDisplayHeight() / 2, uiDevice.getDisplayHeight() / 2, 10);

        // 向下移动
        uiDevice.swipe(uiDevice.getDisplayHeight() / 2, uiDevice.getDisplayHeight() / 2,
                uiDevice.getDisplayHeight() / 2, uiDevice.getDisplayHeight(), 10);
    }

    // 点击应用返回按钮
    UiObject back = uiDevice.findObject(new UiSelector().description("Navigate up"));
    back.click();

    // 点击设备返回按钮
    uiDevice.pressBack();
}
 
开发者ID:alidili,项目名称:Demos,代码行数:41,代码来源:UiTest.java

示例2: startTestActivity

import android.support.test.InstrumentationRegistry; //导入方法依赖的package包/类
@Test
public void startTestActivity() throws Exception {
    final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();

    // start the activity for the first time
    final TestActivity activity = startTestActivity(instrumentation);

    // make sure the attached presenter filled the UI
    Espresso.onView(withId(R.id.helloworld_text))
            .check(matches(allOf(isDisplayed(), withText("Hello World 1"))));

    Espresso.onView(withId(R.id.fragment_helloworld_text))
            .check(matches(allOf(isDisplayed(), withText("Hello World 1"))));

    activity.finish();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:TiPluginTest.java

示例3: testFullLifecycleIncludingConfigurationChange

import android.support.test.InstrumentationRegistry; //导入方法依赖的package包/类
/**
 * Tests the full Activity lifecycle. Guarantees every lifecycle method gets called
 */
@Test
public void testFullLifecycleIncludingConfigurationChange() throws Throwable {
    final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();

    // start the activity for the first time
    final TestActivity activity = startTestActivity(instrumentation);

    // make sure the attached presenter filled the UI
    Espresso.onView(withId(R.id.helloworld_text))
            .check(matches(allOf(isDisplayed(), withText("Hello World 1"))));
    Espresso.onView(withId(R.id.fragment_helloworld_text))
            .check(matches(allOf(isDisplayed(), withText("Hello World 1"))));

    // restart the activity
    rotateOrientation(activity);

    // assert the activity was bound to the presenter. The presenter should update the UI
    // correctly
    Espresso.onView(withId(R.id.helloworld_text))
            .check(matches(allOf(isDisplayed(), withText("Hello World 2"))));
    Espresso.onView(withId(R.id.fragment_helloworld_text))
            .check(matches(allOf(isDisplayed(), withText("Hello World 2"))));

    activity.finish();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:TiPluginTest.java

示例4: setUpScreenshots

import android.support.test.InstrumentationRegistry; //导入方法依赖的package包/类
@Before
public void setUpScreenshots() {
    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    targetContext = instrumentation.getTargetContext();
    device = UiDevice.getInstance(instrumentation);

    // Use this to switch between default strategy and HostScreencap strategy
    //Screengrab.setDefaultScreenshotStrategy(new UiAutomatorScreenshotStrategy());
    Screengrab.setDefaultScreenshotStrategy(new HostScreencapScreenshotStrategy(device));

    device.waitForIdle();
}
 
开发者ID:mozilla-mobile,项目名称:firefox-tv,代码行数:13,代码来源:ScreenshotTest.java

示例5: waitInner

import android.support.test.InstrumentationRegistry; //导入方法依赖的package包/类
private static void waitInner(ReactBridgeIdleSignaler idleSignaler, long timeToWait) {
  // TODO gets broken in gradle, do we need it?
  Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
  long startTime = SystemClock.uptimeMillis();
  boolean bridgeWasIdle = false;
  while (SystemClock.uptimeMillis() - startTime < timeToWait) {
    boolean bridgeIsIdle = idleSignaler.isBridgeIdle();
    if (bridgeIsIdle && bridgeWasIdle) {
      return;
    }
    bridgeWasIdle = bridgeIsIdle;
    long newTimeToWait = Math.max(1, timeToWait - (SystemClock.uptimeMillis() - startTime));
    idleSignaler.waitForIdle(newTimeToWait);
    instrumentation.waitForIdleSync();
  }
  throw new RuntimeException("Timed out waiting for bridge and UI idle!");
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:18,代码来源:ReactIdleDetectionUtil.java

示例6: searchFragmentShouldCollectDisposablesAndReleaseThemInOnDestroy

import android.support.test.InstrumentationRegistry; //导入方法依赖的package包/类
@Test
public void searchFragmentShouldCollectDisposablesAndReleaseThemInOnDestroy() {
    CompositeDisposable composite = new CompositeDisposable();
    decorate().searchFragmentSubcomponent().withCompositeDisposable(() -> composite);
    final MainActivity activity = rule.launchActivity(null);
    final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    instrumentation.runOnMainSync(() ->
    {
        ((ViewPager)activity.findViewById(R.id.container)).setCurrentItem(2);
        assertEquals(1, composite.size());
        activity.finish();
    });
    instrumentation.waitForIdleSync();
    SystemClock.sleep(500);
    assertTrue(composite.isDisposed());
}
 
开发者ID:aschattney,项目名称:dagger-test-example,代码行数:17,代码来源:WeatherFragmentTest.java

示例7: getReactTestFactory

import android.support.test.InstrumentationRegistry; //导入方法依赖的package包/类
public static ReactTestFactory getReactTestFactory() {
  Instrumentation inst = InstrumentationRegistry.getInstrumentation();
  if (!(inst instanceof ReactTestFactory)) {
    return new DefaultReactTestFactory();
  }

  return (ReactTestFactory) inst;
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:9,代码来源:ReactTestHelper.java

示例8: setUp

import android.support.test.InstrumentationRegistry; //导入方法依赖的package包/类
@Override
@Before
public void setUp() {
  mInstrumentation = InstrumentationRegistry.getInstrumentation();
  mWebpBitmapFactory = new WebpBitmapFactoryImpl();
  ImagePipelineConfig.Builder configBuilder =
      ImagePipelineConfig.newBuilder(mInstrumentation.getContext())
          .experiment().setWebpBitmapFactory(mWebpBitmapFactory);
  ImagePipelineFactory.initialize(configBuilder.build());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:WebpBitmapFactoryTest.java

示例9: setUp

import android.support.test.InstrumentationRegistry; //导入方法依赖的package包/类
@Before
public void setUp() {
    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    File dir = getWriteableDir(instrumentation);
    sourceFile = SanitizedFile.knownSanitized(
            AssetUtils.copyAssetToDir(instrumentation.getContext(), "simpleIndex.jar", dir));
    destFile = new SanitizedFile(dir, "dest-" + UUID.randomUUID() + ".testproduct");
    assertFalse(destFile.exists());
    assertTrue(sourceFile.getAbsolutePath() + " should exist.", sourceFile.exists());
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:11,代码来源:FileCompatTest.java

示例10: setUp

import android.support.test.InstrumentationRegistry; //导入方法依赖的package包/类
@Before
public void setUp() {
    instrumentation = InstrumentationRegistry.getInstrumentation();
    File dir = FileCompatTest.getWriteableDir(instrumentation);
    assertTrue(dir.isDirectory());
    assertTrue(dir.canWrite());
    sdk14Apk = AssetUtils.copyAssetToDir(instrumentation.getContext(),
            "org.fdroid.permissions.sdk14.apk",
            dir
    );
    minMaxApk = AssetUtils.copyAssetToDir(instrumentation.getContext(),
            "org.fdroid.permissions.minmax.apk",
            dir
    );
    extendedPermissionsApk = AssetUtils.copyAssetToDir(instrumentation.getContext(),
            "org.fdroid.extendedpermissionstest.apk",
            dir
    );
    extendedPermsXml = AssetUtils.copyAssetToDir(instrumentation.getContext(),
            "extendedPerms.xml",
            dir
    );
    assertTrue(sdk14Apk.exists());
    assertTrue(minMaxApk.exists());
    assertTrue(extendedPermissionsApk.exists());
    assertTrue(extendedPermsXml.exists());
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:28,代码来源:ApkVerifierTest.java

示例11: setUp

import android.support.test.InstrumentationRegistry; //导入方法依赖的package包/类
@Before
public void setUp() {
    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    BcgTestApplication app = (BcgTestApplication) instrumentation.getTargetContext().getApplicationContext();
    ApplicationTestComponent component = (ApplicationTestComponent) BcgApplication.getComponent();

    // inject dagger
    component.inject(this);

    // clear user data before test
    stateManager.clearUser();

    // Set up the stub we want to return in the mock
    LoginResponse loginResponse = new LoginResponse(TEST_USER_ID, TEST_TOKEN);
    Response<LoginResponse> loginResult = Response.success(loginResponse);

    ProfileResponse profileResponse = new ProfileResponse(TEST_EMAIL, TEST_AVATAR);
    Response<ProfileResponse> profileResult = Response.success(profileResponse);

    expectedResult = ProfileModel.create(TEST_EMAIL, TEST_AVATAR);

    // Setup the mock
    when(api.login(eq(TEST_EMAIL), eq(TEST_PASSWORD)))
            .thenReturn(Observable.just(loginResult));
    when(api.getProfile(eq(TEST_TOKEN), eq(TEST_USER_ID)))
            .thenReturn(Observable.just(profileResult));
}
 
开发者ID:mirhoseini,项目名称:bcg,代码行数:28,代码来源:MainActivityTest.java

示例12: removesLocationUpdatesOnStop

import android.support.test.InstrumentationRegistry; //导入方法依赖的package包/类
@Test
public void removesLocationUpdatesOnStop() throws Throwable {
    final MainActivity activity = rule.launchActivity(null);
    final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    instrumentation.runOnMainSync(() -> {
        instrumentation.callActivityOnPause(activity);
        verify(locationService, times(0)).removeUpdates();
        instrumentation.callActivityOnStop(activity);
        verify(locationService).removeUpdates();
    });
    instrumentation.waitForIdleSync();
}
 
开发者ID:aschattney,项目名称:dagger-test-example,代码行数:13,代码来源:SimpleEspressoTest.java

示例13: getInstrumentation

import android.support.test.InstrumentationRegistry; //导入方法依赖的package包/类
Instrumentation getInstrumentation() {
    return InstrumentationRegistry.getInstrumentation();
}
 
开发者ID:Manabu-GT,项目名称:DebugOverlay-Android,代码行数:4,代码来源:DebugOverlayInstrumentedTest.java

示例14: app

import android.support.test.InstrumentationRegistry; //导入方法依赖的package包/类
TestWeatherApplication app() {
    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    return (TestWeatherApplication) instrumentation.getTargetContext().getApplicationContext();
}
 
开发者ID:aschattney,项目名称:dagger-test-example,代码行数:5,代码来源:SimpleEspressoTest.java

示例15: getInstrumentation

import android.support.test.InstrumentationRegistry; //导入方法依赖的package包/类
protected Instrumentation getInstrumentation(){
    return InstrumentationRegistry.getInstrumentation();
}
 
开发者ID:Webtrekk,项目名称:webtrekk-android-sdk,代码行数:4,代码来源:WebtrekkBaseSDKTest.java


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