Move all configuration variables to a new class RunConfiguration.

This commit is contained in:
youtaol
2013-02-18 20:06:16 +08:00
parent 9d6ba74a6d
commit 1e1d93f779
11 changed files with 105 additions and 58 deletions
@@ -15,7 +15,6 @@
*/ */
package com.google.android.apps.mytracks.endtoendtest; package com.google.android.apps.mytracks.endtoendtest;
import com.google.android.apps.mytracks.endtoendtest.others.BigTestUtils;
import android.os.Bundle; import android.os.Bundle;
import android.test.InstrumentationTestRunner; import android.test.InstrumentationTestRunner;
@@ -43,14 +42,14 @@ public class EndToEndTestRunner extends InstrumentationTestRunner {
} }
} }
BigTestUtils.runStressTest = "true".equalsIgnoreCase(arguments.getString("stress")); RunConfiguration.runStressTest = "true".equalsIgnoreCase(arguments.getString("stress"));
BigTestUtils.runSensorTest = "true".equalsIgnoreCase(arguments.getString("sensor")); RunConfiguration.runSensorTest = "true".equalsIgnoreCase(arguments.getString("sensor"));
BigTestUtils.runResourceUsageTest = "true".equalsIgnoreCase(arguments.getString("resource")); RunConfiguration.runResourceUsageTest = "true".equalsIgnoreCase(arguments.getString("resource"));
Log.d(EndToEndTestUtils.LOG_TAG, "Use port number when run test on emulator:" Log.d(EndToEndTestUtils.LOG_TAG, "Use port number when run test on emulator:"
+ EndToEndTestUtils.emulatorPort); + EndToEndTestUtils.emulatorPort);
Log.i(EndToEndTestUtils.LOG_TAG, "Run stress test:" + BigTestUtils.runStressTest); Log.i(EndToEndTestUtils.LOG_TAG, "Run stress test:" + RunConfiguration.runStressTest);
Log.i(EndToEndTestUtils.LOG_TAG, "Run sensor test:" + BigTestUtils.runSensorTest); Log.i(EndToEndTestUtils.LOG_TAG, "Run sensor test:" + RunConfiguration.runSensorTest);
super.onCreate(arguments); super.onCreate(arguments);
} }
@@ -136,6 +136,8 @@ public class EndToEndTestUtils {
public static boolean isCheckedFirstLaunch = false; public static boolean isCheckedFirstLaunch = false;
public static boolean isGooglePlayServicesLatest = true; public static boolean isGooglePlayServicesLatest = true;
private EndToEndTestUtils() {};
/** /**
* Checks the language, then sets the fields with right string. * Checks the language, then sets the fields with right string.
*/ */
@@ -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;
}
}
@@ -30,13 +30,6 @@ import junit.framework.Assert;
*/ */
public class BigTestUtils { 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 DISABLE_MESSAGE = "This test is disabled";
public static final String MYTRACKS_PROCESS_NAME = "com.google.android.maps.mytracks"; public static final String MYTRACKS_PROCESS_NAME = "com.google.android.maps.mytracks";
public static final String MYTRACKS_TEST_INFO_FILE = "MyTracksTestInfo.txt"; public static final String MYTRACKS_TEST_INFO_FILE = "MyTracksTestInfo.txt";
@@ -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.TrackListActivity;
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils; 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.android.maps.mytracks.R;
import android.app.AlertDialog; import android.app.AlertDialog;
@@ -54,7 +55,7 @@ public class ResourceUsageTest extends ActivityInstrumentationTestCase2<TrackLis
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
runTest = BigTestUtils.runResourceUsageTest; runTest = RunConfiguration.runResourceUsageTest;
if (!runTest) { if (!runTest) {
return; return;
} }
@@ -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.TrackListActivity;
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils; 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.android.maps.mytracks.R;
import android.app.Instrumentation; import android.app.Instrumentation;
@@ -46,7 +47,7 @@ public class SensorTest extends ActivityInstrumentationTestCase2<TrackListActivi
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
runTest = BigTestUtils.runSensorTest; runTest = RunConfiguration.runSensorTest;
super.setUp(); super.setUp();
if (!runTest) { if (!runTest) {
return; return;
@@ -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.TrackListActivity;
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils; 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.android.maps.mytracks.R;
import android.app.Instrumentation; import android.app.Instrumentation;
@@ -46,7 +47,7 @@ public class StressTest extends ActivityInstrumentationTestCase2<TrackListActivi
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
runTest = BigTestUtils.runStressTest; runTest = RunConfiguration.runStressTest;
super.setUp(); super.setUp();
if (!runTest) { if (!runTest) {
return; return;
@@ -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.TrackListActivity;
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils; import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
import com.google.android.apps.mytracks.endtoendtest.GoogleUtils; import com.google.android.apps.mytracks.endtoendtest.GoogleUtils;
import com.google.android.apps.mytracks.endtoendtest.RunConfiguration;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
import com.google.api.services.drive.Drive; import com.google.api.services.drive.Drive;
@@ -63,7 +64,7 @@ public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2<Trac
* </ul> * </ul>
*/ */
public void testSyncTracksWithMultiAccounts() throws Exception { public void testSyncTracksWithMultiAccounts() throws Exception {
if (!SyncTestUtils.runSyncTest) { if (!RunConfiguration.getInstance().runSyncTest) {
return; return;
} }
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1); SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1);
@@ -106,7 +107,7 @@ public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2<Trac
* </ul> * </ul>
*/ */
public void testDeleteTracksWithMultiAccounts() throws Exception { public void testDeleteTracksWithMultiAccounts() throws Exception {
if (!SyncTestUtils.runSyncTest) { if (!RunConfiguration.getInstance().runSyncTest) {
return; return;
} }
EndToEndTestUtils.createSimpleTrack(0, true); EndToEndTestUtils.createSimpleTrack(0, true);
@@ -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.TrackListActivity;
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils; 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.android.maps.mytracks.R;
import com.google.api.services.drive.Drive; import com.google.api.services.drive.Drive;
@@ -27,7 +28,8 @@ import android.view.KeyEvent;
import java.io.IOException; 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 * @author Youtao Liu
*/ */
@@ -55,7 +57,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2<
* @throws IOException * @throws IOException
*/ */
public void testDeleteAllTracksInMyTracks() throws IOException { public void testDeleteAllTracksInMyTracks() throws IOException {
if (!SyncTestUtils.runSyncTest) { if (!RunConfiguration.getInstance().runSyncTest) {
return; return;
} }
EndToEndTestUtils.deleteAllTracks(); EndToEndTestUtils.deleteAllTracks();
@@ -70,7 +72,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2<
* @throws IOException * @throws IOException
*/ */
public void testDeleteOneTracksInMyTracks() throws IOException { public void testDeleteOneTracksInMyTracks() throws IOException {
if (!SyncTestUtils.runSyncTest) { if (!RunConfiguration.getInstance().runSyncTest) {
return; return;
} }
EndToEndTestUtils.createTrackIfEmpty(2, false); EndToEndTestUtils.createTrackIfEmpty(2, false);
@@ -90,7 +92,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2<
* @throws IOException * @throws IOException
*/ */
public void testCreateTracksInMyTracks() throws IOException { public void testCreateTracksInMyTracks() throws IOException {
if (!SyncTestUtils.runSyncTest) { if (!RunConfiguration.getInstance().runSyncTest) {
return; return;
} }
EndToEndTestUtils.deleteAllTracks(); EndToEndTestUtils.deleteAllTracks();
@@ -107,7 +109,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2<
* @throws IOException * @throws IOException
*/ */
public void testEditTrackInMyTracks() throws IOException { public void testEditTrackInMyTracks() throws IOException {
if (!SyncTestUtils.runSyncTest) { if (!RunConfiguration.getInstance().runSyncTest) {
return; return;
} }
EndToEndTestUtils.createTrackIfEmpty(3, true); EndToEndTestUtils.createTrackIfEmpty(3, true);
@@ -152,7 +154,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2<
assertTrue(newTrack.indexOf(newType) > 0); assertTrue(newTrack.indexOf(newType) > 0);
assertTrue(newTrack.indexOf(newDesc) > 0); assertTrue(newTrack.indexOf(newDesc) > 0);
} }
@Override @Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
super.tearDown(); super.tearDown();
@@ -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.TrackListActivity;
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils; 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.apps.mytracks.io.sync.SyncUtils;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
import com.google.api.services.drive.Drive; import com.google.api.services.drive.Drive;
@@ -56,7 +57,7 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2<
* @throws IOException * @throws IOException
*/ */
public void testDeleteAllTracksOnDrive() throws IOException { public void testDeleteAllTracksOnDrive() throws IOException {
if (!SyncTestUtils.runSyncTest) { if (!RunConfiguration.getInstance().runSyncTest) {
return; return;
} }
EndToEndTestUtils.createTrackIfEmpty(0, true); EndToEndTestUtils.createTrackIfEmpty(0, true);
@@ -76,7 +77,7 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2<
* @throws IOException * @throws IOException
*/ */
public void testDeleteOneFileOnDrive() throws IOException { public void testDeleteOneFileOnDrive() throws IOException {
if (!SyncTestUtils.runSyncTest) { if (!RunConfiguration.getInstance().runSyncTest) {
return; return;
} }
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
@@ -101,7 +102,7 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2<
* @throws IOException * @throws IOException
*/ */
public void testCreateMyTracksOnDrive() throws IOException { public void testCreateMyTracksOnDrive() throws IOException {
if (!SyncTestUtils.runSyncTest) { if (!RunConfiguration.getInstance().runSyncTest) {
return; return;
} }
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();
@@ -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.TrackListActivity;
import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils; import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils;
import com.google.android.apps.mytracks.endtoendtest.GoogleUtils; 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.sendtogoogle.SendToGoogleUtils;
import com.google.android.apps.mytracks.io.sync.SyncUtils; import com.google.android.apps.mytracks.io.sync.SyncUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.apps.mytracks.util.PreferencesUtils;
@@ -51,7 +52,6 @@ import junit.framework.Assert;
public class SyncTestUtils { public class SyncTestUtils {
public static boolean isCheckedRunSyncTest = false; public static boolean isCheckedRunSyncTest = false;
public static boolean runSyncTest = false;
public static final String KML_FILE_POSTFIX = ".kml"; public static final String KML_FILE_POSTFIX = ".kml";
public static final long MAX_TIME_TO_WAIT_SYNC = 50000; public static final long MAX_TIME_TO_WAIT_SYNC = 50000;
@@ -64,14 +64,13 @@ public class SyncTestUtils {
*/ */
public static Drive setUpForSyncTest(Instrumentation instrumentation, public static Drive setUpForSyncTest(Instrumentation instrumentation,
TrackListActivity trackListActivity) throws IOException, GoogleAuthException { TrackListActivity trackListActivity) throws IOException, GoogleAuthException {
if (runSyncTest || !isCheckedRunSyncTest) { if (RunConfiguration.getInstance().runSyncTest || !isCheckedRunSyncTest) {
EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity); EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity);
} }
if (!isCheckedRunSyncTest) { if (!isCheckedRunSyncTest) {
runSyncTest = canRunSyncTest();
isCheckedRunSyncTest = true; isCheckedRunSyncTest = true;
} }
if (runSyncTest) { if (RunConfiguration.getInstance().runSyncTest) {
EndToEndTestUtils.deleteAllTracks(); EndToEndTestUtils.deleteAllTracks();
SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1); SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1);
Drive drive1 = SyncTestUtils.getGoogleDrive(EndToEndTestUtils.activityMytracks Drive drive1 = SyncTestUtils.getGoogleDrive(EndToEndTestUtils.activityMytracks
@@ -86,29 +85,6 @@ public class SyncTestUtils {
return null; 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. * Gets drive object of Google Drive.
* *
@@ -116,10 +92,10 @@ public class SyncTestUtils {
* @return a Google Drive object * @return a Google Drive object
*/ */
public static Drive getGoogleDrive(Context context) throws IOException, GoogleAuthException { public static Drive getGoogleDrive(Context context) throws IOException, GoogleAuthException {
String googleAccount = PreferencesUtils.getString( String googleAccount = PreferencesUtils.getString(context, R.string.google_account_key,
context, R.string.google_account_key, PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT); PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
GoogleAccountCredential credential = SendToGoogleUtils.getGoogleAccountCredential( GoogleAccountCredential credential = SendToGoogleUtils.getGoogleAccountCredential(context,
context, googleAccount, SendToGoogleUtils.DRIVE_SCOPE); googleAccount, SendToGoogleUtils.DRIVE_SCOPE);
return SyncUtils.getDriveService(credential); return SyncUtils.getDriveService(credential);
} }