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 0eb3256e2..19ff0de9a 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 @@ -13,6 +13,7 @@ * License for the specific language governing permissions and limitations under * the License. */ + package com.google.android.apps.mytracks.endtoendtest; import android.os.Bundle; @@ -20,38 +21,45 @@ import android.test.InstrumentationTestRunner; import android.util.Log; /** - * A test runner can be used to run end-to-end test. + * End-to-end test test runner. * * @author Youtao Liu */ public class EndToEndTestRunner extends InstrumentationTestRunner { - /** - * Gets the parameter port which is used to fix GPS signal to emulators. - */ + private static final String PORT_KEY = "port"; + private static final String RESOURCE_KEY = "resource"; + private static final String SENSOR_KEY = "sensor"; + private static final String STRESS_KEY = "stress"; + private static final String TRUE_VALUE = "true"; + @Override - public void onCreate(Bundle arguments) { - String portNumber = arguments.getString("port"); - if (portNumber != null) { + public void onCreate(Bundle bundle) { + + // Get the emulator port parameter for GPS signals + String port = bundle.getString(PORT_KEY); + if (port != null) { try { - EndToEndTestUtils.emulatorPort = Integer.parseInt(portNumber); + EndToEndTestUtils.emulatorPort = Integer.parseInt(port); } catch (Exception e) { - Log.e(EndToEndTestUtils.LOG_TAG, "Unable to get port parameter, use default value." - + EndToEndTestUtils.emulatorPort, e); + Log.e(EndToEndTestUtils.LOG_TAG, + "Unable to get emulator port parameter, use the default value", e); } } + Log.i(EndToEndTestUtils.LOG_TAG, "Emulator port: " + EndToEndTestUtils.emulatorPort); - RunConfiguration.runStressTest = "true".equalsIgnoreCase(arguments.getString("stress")); - RunConfiguration.runSensorTest = "true".equalsIgnoreCase(arguments.getString("sensor")); - RunConfiguration.runResourceUsageTest = "true" - .equalsIgnoreCase(arguments.getString("resource")); + RunConfiguration runConfiguration = RunConfiguration.getInstance(); - Log.d(EndToEndTestUtils.LOG_TAG, "Use port number when run test on emulator:" - + EndToEndTestUtils.emulatorPort); - Log.i(EndToEndTestUtils.LOG_TAG, "Run stress test:" + RunConfiguration.runStressTest); - Log.i(EndToEndTestUtils.LOG_TAG, "Run sensor test:" + RunConfiguration.runSensorTest); + runConfiguration.setRunResourceTest( + TRUE_VALUE.equalsIgnoreCase(bundle.getString(RESOURCE_KEY))); + Log.i(EndToEndTestUtils.LOG_TAG, "Run resource test: " + runConfiguration.getRunResourceTest()); - super.onCreate(arguments); + runConfiguration.setRunSensorTest(TRUE_VALUE.equalsIgnoreCase(bundle.getString(SENSOR_KEY))); + Log.i(EndToEndTestUtils.LOG_TAG, "Run sensor test: " + runConfiguration.getRunSensorTest()); + + runConfiguration.setRunStressTest(TRUE_VALUE.equalsIgnoreCase(bundle.getString(STRESS_KEY))); + Log.i(EndToEndTestUtils.LOG_TAG, "Run stress test: " + runConfiguration.getRunStressTest()); + + super.onCreate(bundle); } - } 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 index c0fd57da6..60687b4b7 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/RunConfiguration.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/RunConfiguration.java @@ -13,30 +13,23 @@ * 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. + * Run configuration for various tests. * * @author Youtao Liu */ public class RunConfiguration { - private static RunConfiguration instance = null; - + + private static RunConfiguration instance; + /** - * Set to false as default. True to run the test. Default to false since this - * test can take a long time. + * Gets an instance of {@link RunConfiguration}. */ - public static boolean runStressTest = false; - public static boolean runResourceUsageTest = false; - public static boolean runSensorTest = false; - public boolean runSyncTest = false; - - private RunConfiguration() { - runSyncTest = canRunSyncTest(); - } - public static RunConfiguration getInstance() { if (instance == null) { instance = new RunConfiguration(); @@ -44,27 +37,97 @@ public class 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 + /* + * Set to false as default. True to run the test. Default to false since these + * tests can take a long time. */ - public static boolean canRunSyncTest() { - return false; -// 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; + private boolean runResourceTest = false; + private boolean runSensorTest = false; + private boolean runStressTest = false; + private boolean runSyncTest = false; + + private RunConfiguration() { + // Sets run sync test in run-time + setRunSyncTest(canRunSyncTest()); + } + + /** + * Returns true to run the resource test. + */ + public boolean getRunResourceTest() { + return runResourceTest; + } + + /** + * Sets run resource test. + * + * @param run true to run + */ + public void setRunResourceTest(boolean run) { + runResourceTest = run; + } + + /** + * Returns true to run the sensor test. + */ + public boolean getRunSensorTest() { + return runSensorTest; + } + + /** + * Sets run sensor test. + * + * @param run true to run + */ + public void setRunSensorTest(boolean run) { + runSensorTest = run; + } + + /** + * Returns true to run the stress test. + */ + public boolean getRunStressTest() { + return runStressTest; + } + + /** + * Sets run stress test. + * + * @param run true to run + */ + public void setRunStressTest(boolean run) { + runStressTest = run; + } + + /** + * Returns true to run the sync test. + */ + public boolean getRunSyncTest() { + return runSyncTest; + } + + /** + * Sets run sync test. + * + * @param run true to run + */ + public void setRunSyncTest(boolean run) { + runSyncTest = run; + } + + /** + * Returns true if can run the sync test. Needs two specific test accounts on + * the device. + */ + private boolean canRunSyncTest() { + EndToEndTestUtils.findMenuItem( + EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_drive), true); + boolean canRun = 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)); + return canRun; } } 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 a68714695..a85a4e61e 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 @@ -55,7 +55,7 @@ public class ResourceUsageTest extends ActivityInstrumentationTestCase2 */ public void testSyncTracksWithMultiAccounts() throws Exception { - if (!RunConfiguration.getInstance().runSyncTest) { + if (!RunConfiguration.getInstance().getRunSyncTest()) { return; } SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1); @@ -111,7 +111,7 @@ public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2 */ public void testDeleteTracksWithMultiAccounts() throws Exception { - if (!RunConfiguration.getInstance().runSyncTest) { + if (!RunConfiguration.getInstance().getRunSyncTest()) { 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 fd26a3aae..0f68775f9 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 @@ -61,7 +61,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testDeleteAllTracksInMyTracks() throws IOException { - if (!RunConfiguration.getInstance().runSyncTest) { + if (!RunConfiguration.getInstance().getRunSyncTest()) { return; } EndToEndTestUtils.findMenuItem( @@ -75,7 +75,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testDeleteOneTracksInMyTracks() throws IOException { - if (!RunConfiguration.getInstance().runSyncTest) { + if (!RunConfiguration.getInstance().getRunSyncTest()) { return; } EndToEndTestUtils.createTrackIfEmpty(2, false); @@ -95,7 +95,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testCreateTracksInMyTracks() throws IOException { - if (!RunConfiguration.getInstance().runSyncTest) { + if (!RunConfiguration.getInstance().getRunSyncTest()) { return; } EndToEndTestUtils.createSimpleTrack(0, true); @@ -111,7 +111,7 @@ public class SyncDriveWithMyTracksTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testEditTrackInMyTracks() throws IOException { - if (!RunConfiguration.getInstance().runSyncTest) { + if (!RunConfiguration.getInstance().getRunSyncTest()) { return; } EndToEndTestUtils.createTrackIfEmpty(3, true); 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 7ea3a764d..c4c2043f4 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 @@ -61,7 +61,7 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testDeleteAllTracksOnDrive() throws IOException { - if (!RunConfiguration.getInstance().runSyncTest) { + if (!RunConfiguration.getInstance().getRunSyncTest()) { return; } EndToEndTestUtils.createTrackIfEmpty(0, true); @@ -81,7 +81,7 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testDeleteOneFileOnDrive() throws IOException { - if (!RunConfiguration.getInstance().runSyncTest) { + if (!RunConfiguration.getInstance().getRunSyncTest()) { return; } instrumentation.waitForIdleSync(); @@ -106,7 +106,7 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2< * @throws IOException */ public void testCreateMyTracksOnDrive() throws IOException { - if (!RunConfiguration.getInstance().runSyncTest) { + if (!RunConfiguration.getInstance().getRunSyncTest()) { 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 9494f29cb..5dd3633f6 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 @@ -65,13 +65,13 @@ public class SyncTestUtils { */ public static Drive setUpForSyncTest(Instrumentation instrumentation, TrackListActivity trackListActivity) throws IOException, GoogleAuthException { - if (!isCheckedRunSyncTest || RunConfiguration.getInstance().runSyncTest) { + if (!isCheckedRunSyncTest || RunConfiguration.getInstance().getRunSyncTest()) { EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity); } if (!isCheckedRunSyncTest) { isCheckedRunSyncTest = true; } - if (RunConfiguration.getInstance().runSyncTest) { + if (RunConfiguration.getInstance().getRunSyncTest()) { SyncTestUtils.enableSync(GoogleUtils.ACCOUNT_NAME_1); Drive drive1 = SyncTestUtils.getGoogleDrive(EndToEndTestUtils.activityMytracks .getApplicationContext());