diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestRunner.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestRunner.java index cc1831208..0ee2d9b9f 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestRunner.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestRunner.java @@ -15,7 +15,6 @@ */ package com.google.android.apps.mytracks.endtoendtest; -import com.google.android.apps.mytracks.endtoendtest.others.BigTestUtils; import android.os.Bundle; import android.test.InstrumentationTestRunner; @@ -43,14 +42,14 @@ public class EndToEndTestRunner extends InstrumentationTestRunner { } } - BigTestUtils.runStressTest = "true".equalsIgnoreCase(arguments.getString("stress")); - BigTestUtils.runSensorTest = "true".equalsIgnoreCase(arguments.getString("sensor")); - BigTestUtils.runResourceUsageTest = "true".equalsIgnoreCase(arguments.getString("resource")); + RunConfiguration.runStressTest = "true".equalsIgnoreCase(arguments.getString("stress")); + RunConfiguration.runSensorTest = "true".equalsIgnoreCase(arguments.getString("sensor")); + RunConfiguration.runResourceUsageTest = "true".equalsIgnoreCase(arguments.getString("resource")); Log.d(EndToEndTestUtils.LOG_TAG, "Use port number when run test on emulator:" + EndToEndTestUtils.emulatorPort); - Log.i(EndToEndTestUtils.LOG_TAG, "Run stress test:" + BigTestUtils.runStressTest); - Log.i(EndToEndTestUtils.LOG_TAG, "Run sensor test:" + BigTestUtils.runSensorTest); + Log.i(EndToEndTestUtils.LOG_TAG, "Run stress test:" + RunConfiguration.runStressTest); + Log.i(EndToEndTestUtils.LOG_TAG, "Run sensor test:" + RunConfiguration.runSensorTest); super.onCreate(arguments); } diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java index 632468304..8768fc652 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/EndToEndTestUtils.java @@ -136,6 +136,8 @@ public class EndToEndTestUtils { public static boolean isCheckedFirstLaunch = false; public static boolean isGooglePlayServicesLatest = true; + private EndToEndTestUtils() {}; + /** * Checks the language, then sets the fields with right string. */ diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/RunConfiguration.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/RunConfiguration.java new file mode 100644 index 000000000..6ece55d4e --- /dev/null +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/RunConfiguration.java @@ -0,0 +1,70 @@ +/* + * Copyright 2013 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.google.android.apps.mytracks.endtoendtest; + +import com.google.android.maps.mytracks.R; + +/** + * Places all the test configuration in this class. + * + * @author Youtao Liu + */ +public class RunConfiguration { + private static RunConfiguration instance = null; + + /** + * Set to false as default. True to run the test. Default to false since this + * test can take a long time. + */ + public static boolean runStressTest = true; + public static boolean runResourceUsageTest = true; + public static boolean runSensorTest = true; + public boolean runSyncTest = false; + + private RunConfiguration() { + runSyncTest = canRunSyncTest(); + } + + public static RunConfiguration getInstance() { + if (instance == null) { + instance = new RunConfiguration(); + } + return instance; + } + + /** + * 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; + } +} diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/BigTestUtils.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/BigTestUtils.java index 3d42117c6..ab326ea26 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/BigTestUtils.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/BigTestUtils.java @@ -30,13 +30,6 @@ import junit.framework.Assert; */ public class BigTestUtils { - /** - * Set to false as default. True to run the test. Default to false since this - * test can take a long time. - */ - public static boolean runStressTest = true; - public static boolean runSensorTest = true; - public static boolean runResourceUsageTest = true; public static final String DISABLE_MESSAGE = "This test is disabled"; public static final String MYTRACKS_PROCESS_NAME = "com.google.android.maps.mytracks"; public static final String MYTRACKS_TEST_INFO_FILE = "MyTracksTestInfo.txt"; diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/ResourceUsageTest.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/ResourceUsageTest.java index 763357506..a68714695 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/ResourceUsageTest.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/others/ResourceUsageTest.java @@ -17,6 +17,7 @@ package com.google.android.apps.mytracks.endtoendtest.others; import com.google.android.apps.mytracks.TrackListActivity; import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils; +import com.google.android.apps.mytracks.endtoendtest.RunConfiguration; import com.google.android.maps.mytracks.R; import android.app.AlertDialog; @@ -54,7 +55,7 @@ public class ResourceUsageTest extends ActivityInstrumentationTestCase2 */ public void testSyncTracksWithMultiAccounts() throws Exception { - if (!SyncTestUtils.runSyncTest) { + if (!RunConfiguration.getInstance().runSyncTest) { return; } SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1); @@ -106,7 +107,7 @@ public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2 */ public void testDeleteTracksWithMultiAccounts() throws Exception { - if (!SyncTestUtils.runSyncTest) { + if (!RunConfiguration.getInstance().runSyncTest) { return; } EndToEndTestUtils.createSimpleTrack(0, true); diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncDriveWithMyTracksTest.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncDriveWithMyTracksTest.java index a10273236..497d83922 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncDriveWithMyTracksTest.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncDriveWithMyTracksTest.java @@ -17,6 +17,7 @@ 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.RunConfiguration; import com.google.android.maps.mytracks.R; import com.google.api.services.drive.Drive; @@ -27,7 +28,8 @@ import android.view.KeyEvent; import java.io.IOException; /** - * Tests making changes on Google Drive when syncing My Tracks with Google Drive. + * Tests making changes on Google Drive when syncing My Tracks with Google + * Drive. * * @author Youtao Liu */ @@ -55,7 +57,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testDeleteAllTracksInMyTracks() throws IOException { - if (!SyncTestUtils.runSyncTest) { + if (!RunConfiguration.getInstance().runSyncTest) { return; } EndToEndTestUtils.deleteAllTracks(); @@ -70,7 +72,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testDeleteOneTracksInMyTracks() throws IOException { - if (!SyncTestUtils.runSyncTest) { + if (!RunConfiguration.getInstance().runSyncTest) { return; } EndToEndTestUtils.createTrackIfEmpty(2, false); @@ -90,7 +92,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testCreateTracksInMyTracks() throws IOException { - if (!SyncTestUtils.runSyncTest) { + if (!RunConfiguration.getInstance().runSyncTest) { return; } EndToEndTestUtils.deleteAllTracks(); @@ -107,7 +109,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testEditTrackInMyTracks() throws IOException { - if (!SyncTestUtils.runSyncTest) { + if (!RunConfiguration.getInstance().runSyncTest) { return; } EndToEndTestUtils.createTrackIfEmpty(3, true); @@ -152,7 +154,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2< assertTrue(newTrack.indexOf(newType) > 0); assertTrue(newTrack.indexOf(newDesc) > 0); } - + @Override protected void tearDown() throws Exception { super.tearDown(); diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncMyTracksWithDriveTest.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncMyTracksWithDriveTest.java index 4a402b3b2..f6ceb334e 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncMyTracksWithDriveTest.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncMyTracksWithDriveTest.java @@ -17,6 +17,7 @@ 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.RunConfiguration; import com.google.android.apps.mytracks.io.sync.SyncUtils; import com.google.android.maps.mytracks.R; import com.google.api.services.drive.Drive; @@ -56,7 +57,7 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testDeleteAllTracksOnDrive() throws IOException { - if (!SyncTestUtils.runSyncTest) { + if (!RunConfiguration.getInstance().runSyncTest) { return; } EndToEndTestUtils.createTrackIfEmpty(0, true); @@ -76,7 +77,7 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testDeleteOneFileOnDrive() throws IOException { - if (!SyncTestUtils.runSyncTest) { + if (!RunConfiguration.getInstance().runSyncTest) { return; } instrumentation.waitForIdleSync(); @@ -101,7 +102,7 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testCreateMyTracksOnDrive() throws IOException { - if (!SyncTestUtils.runSyncTest) { + if (!RunConfiguration.getInstance().runSyncTest) { return; } instrumentation.waitForIdleSync(); diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncTestUtils.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncTestUtils.java index 9a9f0eb38..3e27d62b3 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncTestUtils.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncTestUtils.java @@ -18,6 +18,7 @@ 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.endtoendtest.RunConfiguration; import com.google.android.apps.mytracks.io.sendtogoogle.SendToGoogleUtils; import com.google.android.apps.mytracks.io.sync.SyncUtils; import com.google.android.apps.mytracks.util.PreferencesUtils; @@ -51,7 +52,6 @@ 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; @@ -64,14 +64,13 @@ public class SyncTestUtils { */ public static Drive setUpForSyncTest(Instrumentation instrumentation, TrackListActivity trackListActivity) throws IOException, GoogleAuthException { - if (runSyncTest || !isCheckedRunSyncTest) { + if (RunConfiguration.getInstance().runSyncTest || !isCheckedRunSyncTest) { EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity); } if (!isCheckedRunSyncTest) { - runSyncTest = canRunSyncTest(); isCheckedRunSyncTest = true; } - if (runSyncTest) { + if (RunConfiguration.getInstance().runSyncTest) { EndToEndTestUtils.deleteAllTracks(); SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1); Drive drive1 = SyncTestUtils.getGoogleDrive(EndToEndTestUtils.activityMytracks @@ -86,29 +85,6 @@ public class SyncTestUtils { 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; - } - /** * Gets drive object of Google Drive. * @@ -116,10 +92,10 @@ public class SyncTestUtils { * @return a Google Drive object */ public static Drive getGoogleDrive(Context context) throws IOException, GoogleAuthException { - String googleAccount = PreferencesUtils.getString( - context, R.string.google_account_key, PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT); - GoogleAccountCredential credential = SendToGoogleUtils.getGoogleAccountCredential( - context, googleAccount, SendToGoogleUtils.DRIVE_SCOPE); + String googleAccount = PreferencesUtils.getString(context, R.string.google_account_key, + PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT); + GoogleAccountCredential credential = SendToGoogleUtils.getGoogleAccountCredential(context, + googleAccount, SendToGoogleUtils.DRIVE_SCOPE); return SyncUtils.getDriveService(credential); }