/** * The Android library module's own tests, independent from the main app. */ @RunWith(AndroidJUnit4.class) @MediumTest public class AndroidLibraryModuleTest { private Context mContext; @Before public void initTargetContext() { mContext = InstrumentationRegistry.getTargetContext(); assertThat(mContext, notNullValue()); } @Test public void verifyResourceFromLibrary() { assertThat(mContext.getString(R.string.library_module_hello_world), is(equalTo("Hello from an Android library module!"))); } @Test public void verifyClassFromLibrary() { AndroidLibraryModuleClass libraryModuleInstance = new AndroidLibraryModuleClass(); assertThat(libraryModuleInstance.isReady(), is(true)); } }
@MediumTest public void testLaunchingWithValidNativeLinkingNoUserIntent() throws Exception { final TestBlocker blocker = getTestBlocker();
@MediumTest @LargeTest public void testStaticExecuteMyFriendsAsync() { final AccessToken accessToken = getAccessTokenForSharedUser(); class FriendsCallback extends ExpectSuccessCallback implements GraphRequest.GraphJSONArrayCallback { @Override public void onCompleted(JSONArray friends, GraphResponse response) { assertNotNull(friends); RequestTests.validateMyFriendsResponse(response); onCompleted(response); } } runOnBlockerThread(new Runnable() { @Override public void run() { GraphRequest.newMyFriendsRequest(accessToken, new FriendsCallback()).executeAsync(); } }, false); waitAndAssertSuccess(1); }
@MediumTest @LargeTest public void testStaticExecuteMeAsync() { final AccessToken accessToken = getAccessTokenForSharedUser(); class MeCallback extends ExpectSuccessCallback implements GraphRequest.GraphJSONObjectCallback { @Override public void onCompleted(JSONObject me, GraphResponse response) { assertNotNull(me); assertEquals(accessToken.getUserId(), me.optString("id")); RequestTests.validateMeResponse(accessToken, response); onCompleted(response); } } runOnBlockerThread(new Runnable() { @Override public void run() { GraphRequest.newMeRequest(accessToken, new MeCallback()).executeAsync(); } }, false); waitAndAssertSuccess(1); }
@MediumTest @LargeTest public void testShortTimeoutCausesFailure() { final AccessToken accessToken = getAccessTokenForSharedUser(); GraphRequest request = new GraphRequest(accessToken, "me/likes", null, null, new ExpectFailureCallback()); GraphRequestBatch requestBatch = new GraphRequestBatch(request); // 1 millisecond timeout should be too short for response from server. requestBatch.setTimeout(1); TestGraphRequestAsyncTask task = new TestGraphRequestAsyncTask(requestBatch); task.executeOnBlockerThread(); // Note: plus 1, because the overall async task signals as well. waitAndAssertSuccess(2); }
@MediumTest public class DocumentCentricAppsUnitTest extends ActivityUnitTestCase<DocumentCentricActivity> {
/** * Test basic startup/shutdown of Application */ @MediumTest public void testSimpleCreate() { createApplication(); }
/** * Test basic startup/shutdown of Application */ @MediumTest public void testSimpleCreate() { createApplication(); }
@MediumTest public void test600k() throws Throwable { template(600); }
@MediumTest public void test600k2() throws Throwable { template2(600); }
@MediumTest public class MusicAPITest extends AndroidTestCase {
/** * Test binding to service */ @MediumTest public void testBindable() { Intent startIntent = new Intent(); startIntent.setClass(getContext(), LocalService.class); IBinder service = bindService(startIntent); }
/** * Test binding to service */ @MediumTest public void testBindable() { Intent startIntent = new Intent(); startIntent.setClass(getContext(), LocalService.class); IBinder service = bindService(startIntent); }
@MediumTest public void test0File() throws Throwable { final String expectKey = "世/界"; final File f = TempFile.createFile(0); Map<String, String> params = new HashMap<String, String>(); params.put("x:foo", "fooval"); final UploadOptions opt = new UploadOptions(params, null, true, null, null); info = uploadManager.syncPut(f, expectKey, TestConfig.token_z0, opt); resp = info.response; Assert.assertEquals(f.toString(), 0, f.length()); Assert.assertEquals(info.toString(), ResponseInfo.ZeroSizeFile, info.statusCode); Assert.assertNull(resp); Assert.assertFalse(info.toString(), info.isOK()); Assert.assertEquals(info.toString(), "", info.reqId); TempFile.remove(f); }
@MediumTest public void testFile() throws Throwable { final String expectKey = "世/界"; final File f = TempFile.createFile(1); Map<String, String> params = new HashMap<String, String>(); params.put("x:foo", "fooval"); final UploadOptions opt = new UploadOptions(params, null, true, null, null); info = uploadManager.syncPut(f, expectKey, TestConfig.token_z0, opt); resp = info.response; // key = resp.optString("key"); // Assert.assertEquals(info.toString(), expectKey, key); // Assert.assertTrue(info.toString(), info.isOK()); //上传策略含空格 \"fname\":\" $(fname) \" // Assert.assertEquals(f.getName(), resp.optString("fname", "res doesn't include the FNAME").trim()); Assert.assertNotNull(info.reqId); // Assert.assertNotNull(resp); // String hash = resp.getString("hash"); // Assert.assertEquals(hash, Etag.file(f)); TempFile.remove(f); }
@MediumTest public void testGoingRightFromLeftButtonJumpsOverCenterToRight() { sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT); assertTrue("right button should be focused", mRightButton.isFocused()); }
@MediumTest public void testGoingRightFromLeftButtonJumpsOverCenterToRight() { sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT); assertTrue("right button should be focused", mRightButton.isFocused()); }
@MediumTest public void testRotate() throws Throwable { getActivity().startActivity(intent); final ImageView btn = (ImageView) getActivity().findViewById(R.id.go); runTestOnUiThread(new Runnable() { @Override public void run() { btn.performClick(); } }); }
/** * The name 'test preconditions' is a convention to signal that if this * test doesn't pass, the test case was not set up properly and it might * explain any and all failures in other tests. This is not guaranteed * to run before other tests, as junit uses reflection to find the tests. */ @MediumTest public void testPreconditions() { startActivity(mStartIntent, null, null); mButton = (Button) getActivity().findViewById(R.id.go); assertNotNull(getActivity()); assertNotNull(mButton); }
/** * The name 'test preconditions' is a convention to signal that if this * test doesn't pass, the test case was not set up properly and it might * explain any and all failures in other tests. This is not guaranteed * to run before other tests, as junit uses reflection to find the tests. */ @MediumTest public void testPreconditions() { startActivity(mStartIntent, null, null); mButton = (Button) getActivity().findViewById(R.id.go); assertNotNull(getActivity()); assertNotNull(mButton); }