forked from upstream-mirrors/OpenTracks
Code cleanup: EndToEndTestRunner and RunConfiguration
This commit is contained in:
+28
-20
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+98
-35
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ public class ResourceUsageTest extends ActivityInstrumentationTestCase2<TrackLis
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
runTest = RunConfiguration.runResourceUsageTest;
|
||||
runTest = RunConfiguration.getInstance().getRunResourceTest();
|
||||
if (!runTest) {
|
||||
return;
|
||||
}
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ public class SensorTest extends ActivityInstrumentationTestCase2<TrackListActivi
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
runTest = RunConfiguration.runSensorTest;
|
||||
runTest = RunConfiguration.getInstance().getRunSensorTest();
|
||||
super.setUp();
|
||||
if (!runTest) {
|
||||
return;
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ public class StressTest extends ActivityInstrumentationTestCase2<TrackListActivi
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
runTest = RunConfiguration.runStressTest;
|
||||
runTest = RunConfiguration.getInstance().getRunStressTest();
|
||||
super.setUp();
|
||||
if (!runTest) {
|
||||
return;
|
||||
|
||||
+2
-2
@@ -68,7 +68,7 @@ public class MultiAccountsSyncTest extends ActivityInstrumentationTestCase2<Trac
|
||||
* </ul>
|
||||
*/
|
||||
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<Trac
|
||||
* </ul>
|
||||
*/
|
||||
public void testDeleteTracksWithMultiAccounts() throws Exception {
|
||||
if (!RunConfiguration.getInstance().runSyncTest) {
|
||||
if (!RunConfiguration.getInstance().getRunSyncTest()) {
|
||||
return;
|
||||
}
|
||||
EndToEndTestUtils.createSimpleTrack(0, true);
|
||||
|
||||
+4
-4
@@ -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);
|
||||
|
||||
+3
-3
@@ -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();
|
||||
|
||||
+2
-2
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user