Make sync tests can only be run on device bound with two test accounts for sync tests can not be run in parallel.

This commit is contained in:
youtaol
2013-01-31 14:45:47 +08:00
parent 880f153ed2
commit 7aef17625c
4 changed files with 112 additions and 28 deletions
@@ -33,7 +33,7 @@ import java.io.IOException;
*/
public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
public static Drive drive;
private Drive drive;
private Instrumentation instrumentation;
private TrackListActivity trackListActivity;
@@ -46,9 +46,7 @@ public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2<Trac
super.setUp();
instrumentation = getInstrumentation();
trackListActivity = getActivity();
EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity);
drive = SyncTestUtils.setUpForSyncTest(GoogleUtils.ACCOUNT_NAME_1);
EndToEndTestUtils.deleteAllTracks();
drive = SyncTestUtils.setUpForSyncTest(instrumentation, trackListActivity);
}
/**
@@ -57,6 +55,10 @@ public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2<Trac
* @throws IOException
*/
public void testSyncTracksWithMultiAccounts() throws IOException {
if (!SyncTestUtils.runSyncTest) {
return;
}
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1);
// Create tracks with first track.
EndToEndTestUtils.createSimpleTrack(0, true);
@@ -67,14 +69,14 @@ public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2<Trac
// Sync with Google Drive and then check it of the second account.
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
drive = SyncTestUtils.setUpForSyncTest(GoogleUtils.ACCOUNT_NAME_2);
drive = SyncTestUtils.getGoogleDrive(trackListActivity.getApplicationContext());
SyncTestUtils.checkFilesNumber(drive);
// Check Google Drive of the first account.
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1);
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
drive = SyncTestUtils.setUpForSyncTest(GoogleUtils.ACCOUNT_NAME_1);
drive = SyncTestUtils.getGoogleDrive(trackListActivity.getApplicationContext());
SyncTestUtils.checkFilesNumber(drive);
}
@@ -86,6 +88,9 @@ public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2<Trac
* @throws IOException
*/
public void testDeleteTracksWithMultiAccounts() throws IOException {
if (!SyncTestUtils.runSyncTest) {
return;
}
EndToEndTestUtils.createSimpleTrack(0, true);
EndToEndTestUtils.createSimpleTrack(0, true);
EndToEndTestUtils.createSimpleTrack(0, true);
@@ -95,6 +100,8 @@ public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2<Trac
.getChildAt(0));
EndToEndTestUtils.SOLO.clickOnMenuItem(EndToEndTestUtils.activityMytracks
.getString(R.string.menu_delete));
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
.getString(R.string.generic_ok));
// Switch account and delete another track.
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_2);
@@ -102,21 +109,28 @@ public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2<Trac
.getChildAt(0));
EndToEndTestUtils.SOLO.clickOnMenuItem(EndToEndTestUtils.activityMytracks
.getString(R.string.menu_delete));
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
.getString(R.string.generic_ok));
// Check Google Drive of the first account.
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1);
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
drive = SyncTestUtils.setUpForSyncTest(GoogleUtils.ACCOUNT_NAME_1);
drive = SyncTestUtils.getGoogleDrive(trackListActivity.getApplicationContext());
SyncTestUtils.checkFilesNumber(drive);
// Check Google Drive of the second account.
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_2);
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
drive = SyncTestUtils.setUpForSyncTest(GoogleUtils.ACCOUNT_NAME_2);
drive = SyncTestUtils.getGoogleDrive(trackListActivity.getApplicationContext());
SyncTestUtils.checkFilesNumber(drive);
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
EndToEndTestUtils.SOLO.finishOpenedActivities();
}
}
@@ -17,7 +17,6 @@ package com.google.android.apps.mytracks.endtoendtest.sync;
import com.google.android.apps.mytracks.TrackListActivity;
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
import com.google.android.apps.mytracks.endtoendtest.GoogleUtils;
import com.google.android.maps.mytracks.R;
import com.google.api.services.drive.Drive;
@@ -34,7 +33,7 @@ import java.io.IOException;
*/
public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
public static Drive drive;
private Drive drive;
private Instrumentation instrumentation;
private TrackListActivity trackListActivity;
@@ -47,8 +46,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2<
super.setUp();
instrumentation = getInstrumentation();
trackListActivity = getActivity();
EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity);
drive = SyncTestUtils.setUpForSyncTest(GoogleUtils.ACCOUNT_NAME_1);
drive = SyncTestUtils.setUpForSyncTest(instrumentation, trackListActivity);
}
/**
@@ -57,6 +55,9 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2<
* @throws IOException
*/
public void testDeleteAllTracksInMyTracks() throws IOException {
if (!SyncTestUtils.runSyncTest) {
return;
}
EndToEndTestUtils.deleteAllTracks();
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
@@ -69,6 +70,9 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2<
* @throws IOException
*/
public void testDeleteOneTracksInMyTracks() throws IOException {
if (!SyncTestUtils.runSyncTest) {
return;
}
EndToEndTestUtils.createTrackIfEmpty(2, false);
EndToEndTestUtils.SOLO.clickOnMenuItem(EndToEndTestUtils.activityMytracks
.getString(R.string.menu_delete));
@@ -86,6 +90,9 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2<
* @throws IOException
*/
public void testCreateTracksInMyTracks() throws IOException {
if (!SyncTestUtils.runSyncTest) {
return;
}
EndToEndTestUtils.deleteAllTracks();
EndToEndTestUtils.createSimpleTrack(0, true);
EndToEndTestUtils.createSimpleTrack(3, true);
@@ -100,6 +107,9 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2<
* @throws IOException
*/
public void testEditTrackInMyTracks() throws IOException {
if (!SyncTestUtils.runSyncTest) {
return;
}
EndToEndTestUtils.createTrackIfEmpty(3, true);
// Sync this track.
@@ -142,4 +152,10 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2<
assertTrue(newTrack.indexOf(newType) > 0);
assertTrue(newTrack.indexOf(newDesc) > 0);
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
EndToEndTestUtils.SOLO.finishOpenedActivities();
}
}
@@ -17,7 +17,6 @@ package com.google.android.apps.mytracks.endtoendtest.sync;
import com.google.android.apps.mytracks.TrackListActivity;
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
import com.google.android.apps.mytracks.endtoendtest.GoogleUtils;
import com.google.android.maps.mytracks.R;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.File;
@@ -34,7 +33,7 @@ import java.io.IOException;
*/
public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
public static Drive drive;
private Drive drive;
private Instrumentation instrumentation;
private TrackListActivity trackListActivity;
@@ -47,8 +46,7 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2<
super.setUp();
instrumentation = getInstrumentation();
trackListActivity = getActivity();
EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity);
drive = SyncTestUtils.setUpForSyncTest(GoogleUtils.ACCOUNT_NAME_1);
drive = SyncTestUtils.setUpForSyncTest(instrumentation, trackListActivity);
}
/**
@@ -57,7 +55,9 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2<
* @throws IOException
*/
public void testDeleteAllTracksOnDrive() throws IOException {
EndToEndTestUtils.deleteAllTracks();
if (!SyncTestUtils.runSyncTest) {
return;
}
EndToEndTestUtils.createTrackIfEmpty(0, true);
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
@@ -68,14 +68,16 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2<
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
SyncTestUtils.checkTracksNumber(0);
}
/**
* Deletes one file on Google Drive and checks it in MyTracks.
*
* @throws IOException
*/
public void testDeleteOneFileOnDrive() throws IOException {
EndToEndTestUtils.deleteAllTracks();
if (!SyncTestUtils.runSyncTest) {
return;
}
instrumentation.waitForIdleSync();
EndToEndTestUtils.createSimpleTrack(0, true);
EndToEndTestUtils.createSimpleTrack(0, true);
@@ -91,14 +93,16 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2<
SyncTestUtils.checkFilesNumber(drive);
SyncTestUtils.checkTracksNumber(1);
}
/**
* Tests deleting and creating MyTracks folder on Google Dive by MyTracks.
*
* @throws IOException
*/
public void testCreateMyTracksOnDrive() throws IOException {
EndToEndTestUtils.deleteAllTracks();
if (!SyncTestUtils.runSyncTest) {
return;
}
instrumentation.waitForIdleSync();
EndToEndTestUtils.createSimpleTrack(0, true);
EndToEndTestUtils.createSimpleTrack(0, true);
@@ -108,7 +112,7 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2<
SyncTestUtils.checkFilesNumber(drive);
File folder = SyncTestUtils.getMyTracksFolder(trackListActivity.getApplicationContext(), drive);
assertNotNull(folder);
SyncTestUtils.removeFile(folder, drive);
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true);
@@ -15,7 +15,9 @@
*/
package com.google.android.apps.mytracks.endtoendtest.sync;
import com.google.android.apps.mytracks.TrackListActivity;
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
import com.google.android.apps.mytracks.endtoendtest.GoogleUtils;
import com.google.android.apps.mytracks.io.sync.SyncUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R;
@@ -27,6 +29,7 @@ import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.File;
import com.google.api.services.drive.model.FileList;
import android.app.Instrumentation;
import android.content.Context;
import android.util.Log;
import android.widget.CheckBox;
@@ -48,18 +51,64 @@ import junit.framework.Assert;
*/
public class SyncTestUtils {
public static boolean isCheckedRunSyncTest = false;
public static boolean runSyncTest = false;
public static final String KML_FILE_POSTFIX = ".kml";
public static final long MAX_TIME_TO_WAIT_SYNC = 50000;
/**
* Setups sync tests.
*
* @param accountName the name of account
* @return drive object of Goolge Drive
* @param instrumentation the instrumentation is used for test
* @param trackListActivity the startup activity
* @return the drive object of current account
* @throws IOException
*/
public static Drive setUpForSyncTest(String accountName) {
SyncTestUtils.enableSync(accountName);
return SyncTestUtils.getGoogleDrive(EndToEndTestUtils.activityMytracks.getApplicationContext());
public static Drive setUpForSyncTest(Instrumentation instrumentation,
TrackListActivity trackListActivity) throws IOException {
if (runSyncTest || !isCheckedRunSyncTest) {
EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity);
}
if (!isCheckedRunSyncTest) {
runSyncTest = canRunSyncTest();
isCheckedRunSyncTest = true;
}
if (runSyncTest) {
EndToEndTestUtils.deleteAllTracks();
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1);
Drive drive1 = SyncTestUtils.getGoogleDrive(EndToEndTestUtils.activityMytracks
.getApplicationContext());
removeKMLFiles(drive1);
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_2);
Drive drive2 = SyncTestUtils.getGoogleDrive(EndToEndTestUtils.activityMytracks
.getApplicationContext());
removeKMLFiles(drive2);
return drive2;
}
return null;
}
/**
* Runs sync tests when both test accounts are bound with the devices.
*
* @return true means can run sync tests in this device
*/
public static boolean canRunSyncTest() {
EndToEndTestUtils.findMenuItem(
EndToEndTestUtils.activityMytracks.getString(R.string.menu_settings), true);
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
.getString(R.string.settings_google));
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
.getString(R.string.settings_google_account_title));
boolean canRunSyncE2ETest = EndToEndTestUtils.SOLO.waitForText(GoogleUtils.ACCOUNT_NAME_1, 1,
EndToEndTestUtils.SHORT_WAIT_TIME)
&& EndToEndTestUtils.SOLO.waitForText(GoogleUtils.ACCOUNT_NAME_2, 1,
EndToEndTestUtils.TINY_WAIT_TIME);
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
.getString(R.string.generic_cancel));
EndToEndTestUtils.SOLO.goBack();
EndToEndTestUtils.SOLO.goBack();
return canRunSyncE2ETest;
}
/**
@@ -85,7 +134,7 @@ public class SyncTestUtils {
*/
public static List<File> updateDriveFiles(Context context, Drive drive) throws IOException {
File folder = SyncTestUtils.getMyTracksFolder(context, drive);
if ( folder == null) {
if (folder == null) {
return new ArrayList<File>();
}
String folderId = folder.getId();
@@ -180,6 +229,7 @@ public class SyncTestUtils {
EndToEndTestUtils.activityMytracks.getString(
R.string.settings_google_drive_sync_confirm_message).split("%")[0], 1,
EndToEndTestUtils.SHORT_WAIT_TIME);
Assert.assertTrue(EndToEndTestUtils.SOLO.searchText(accountName, true));
EndToEndTestUtils.SOLO.clickOnText(EndToEndTestUtils.activityMytracks
.getString(R.string.generic_ok));
}