當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。