本文整理匯總了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();
}
示例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();
}
示例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();
}
示例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();
}
示例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!");
}
示例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());
}
示例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;
}
示例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());
}
示例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());
}
示例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());
}
示例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));
}
示例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();
}
示例13: getInstrumentation
import android.support.test.InstrumentationRegistry; //導入方法依賴的package包/類
Instrumentation getInstrumentation() {
return InstrumentationRegistry.getInstrumentation();
}
示例14: app
import android.support.test.InstrumentationRegistry; //導入方法依賴的package包/類
TestWeatherApplication app() {
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
return (TestWeatherApplication) instrumentation.getTargetContext().getApplicationContext();
}
示例15: getInstrumentation
import android.support.test.InstrumentationRegistry; //導入方法依賴的package包/類
protected Instrumentation getInstrumentation(){
return InstrumentationRegistry.getInstrumentation();
}