Unit test Dropbox Datastore API on Android

I want to unit test my own request requests (CRUD) in the Datastore API on Android .

Robolectric

I tried using Robolectric . This is part of my test code:

TestActivity activity;

@Before
public void setup() {
    this.activity = Robolectric.buildActivity(TestActivity.class).create().get();
}

@Test
public void shouldHaveHappySmiles() throws Exception {
    assertTrue(activity.getAccount().isLinked());
}

      

I am initializing an instance in my TestActivity which is inside my application code. Here's the important piece of code:

import com.dropbox.sync.android.DbxAccount;
import com.dropbox.sync.android.DbxAccountManager;

    public class TestActivity extends Activity {

    private DbxAccountManager mDbxAcctMgr;
    private DbxAccount mAccount;

    public DbxAccount getAccount() {
            mDbxAcctMgr = DbxAccountManager.getInstance(getApplicationContext(), "xxx", "zzz");
            mAccount = DropboxUtils.getLinkedAccount(mDbxAcctMgr);
            return mAccount;
    }
}

      

This is the line where it falls:

DbxAccountManager.getInstance(getApplicationContext(), "xxx", "zzz");

      

Stacktrace message and error message:

com.dropbox.sync.android.DbxRuntimeException$BadState: Required Sync API Activity isn't included in application manifest: com.dropbox.client2.android.AuthActivity, com.dropbox.sync.android.DbxAuthActivity
at com.dropbox.sync.android.CoreAndroidUtil.validateHaveAuthActivities(CoreAndroidUtil.java:244)
at com.dropbox.sync.android.DbxAccountManager.validateAppContext(DbxAccountManager.java:511)
at com.dropbox.sync.android.DbxAccountManager.getInstance(DbxAccountManager.java:193)
at com.dropbox.sync.android.DbxAccountManager.getInstance(DbxAccountManager.java:160)
at com.dropbox.sync.android.DbxAccountManager.getInstance(DbxAccountManager.java:107)

      

Required actions in my manifest:

<activity android:name="com.dropbox.sync.android.DbxAuthActivity" />
<activity
    android:name="com.dropbox.client2.android.AuthActivity"
    android:launchMode="singleTask" >
    <intent-filter>
        <data android:scheme="db-zzz" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
<service
    android:name="com.dropbox.sync.android.DbxSyncService"
    android:enabled="true"
    android:exported="false"
    android:label="Dropbox Sync" />

      

In production mode (so when you just use the app) there is no such error.

Appium

I have also tried to validate my requests using Appium . My idea was to run the application through Appium and then run some test code without letting Appium press any button. For example. insert some data and check if it is inserted correctly - all in the test method. For this I need an instance of the current Activity (android.app.Activity). As far as I know, there is a method called AppiumDriver.getCurrentActivity (), but it returns the Activity name as a String and there seems to be no way to get an android.app.Activity instance.

I'm looking for an answer that explains in detail how to set up the required test tool (Appium, Robolectric, or whatever) in Android Studio 1.0 Release Candidate 2 (at the time of this writing) and have at least one test pass requests the Datastore API version 3.1.1 Dropbox on Android.

+3


source to share





All Articles