Add two parameters to EndToEndTestRunner to control the sensor test and stress test for these two test need long time to run.

This commit is contained in:
youtaol
2012-12-04 11:05:18 +08:00
parent db3194224b
commit 1c36a82fe2
4 changed files with 51 additions and 20 deletions
@@ -15,6 +15,8 @@
*/ */
package com.google.android.apps.mytracks.endtoendtest; package com.google.android.apps.mytracks.endtoendtest;
import com.google.android.apps.mytracks.endtoendtest.others.SecondaryTestUtils;
import android.os.Bundle; import android.os.Bundle;
import android.test.InstrumentationTestRunner; import android.test.InstrumentationTestRunner;
import android.util.Log; import android.util.Log;
@@ -31,13 +33,35 @@ public class EndToEndTestRunner extends InstrumentationTestRunner {
*/ */
@Override @Override
public void onCreate(Bundle arguments) { public void onCreate(Bundle arguments) {
try { String portNumber = arguments.getString("port");
EndToEndTestUtils.emulatorPort = Integer.parseInt(arguments.getString("port")); if (portNumber != null) {
} catch (Exception e) { try {
Log.e(EndToEndTestUtils.LOG_TAG, "Unable to get port parameter, use default value." + EndToEndTestUtils.emulatorPort, e); EndToEndTestUtils.emulatorPort = Integer.parseInt(portNumber);
} catch (Exception e) {
Log.e(EndToEndTestUtils.LOG_TAG, "Unable to get port parameter, use default value."
+ EndToEndTestUtils.emulatorPort, e);
}
} }
Log.d(EndToEndTestUtils.LOG_TAG, "Use port number when run test on emulator:" + EndToEndTestUtils.emulatorPort);
String isStressTest = arguments.getString("stress");
if (isStressTest != null && isStressTest.equalsIgnoreCase("true")) {
SecondaryTestUtils.runStressTest = true;
} else {
SecondaryTestUtils.runStressTest = false;
}
String isSensorTest = arguments.getString("sensor");
if (isSensorTest != null && isSensorTest.equalsIgnoreCase("true")) {
SecondaryTestUtils.runSensorTest = true;
} else {
SecondaryTestUtils.runSensorTest = false;
}
Log.d(EndToEndTestUtils.LOG_TAG, "Use port number when run test on emulator:"
+ EndToEndTestUtils.emulatorPort);
Log.i(EndToEndTestUtils.LOG_TAG, "Run stress test:" + SecondaryTestUtils.runStressTest);
Log.i(EndToEndTestUtils.LOG_TAG, "Run sensor test:" + SecondaryTestUtils.runSensorTest);
super.onCreate(arguments); super.onCreate(arguments);
} }
@@ -6,7 +6,9 @@ public class SecondaryTestUtils {
* Set to false as default. True to run the test. Default to false since this * Set to false as default. True to run the test. Default to false since this
* test can take a long time. * test can take a long time.
*/ */
protected static boolean runTest = true; public static boolean runStressTest = false;
public static boolean runSensorTest = false;
protected static final String DISABLE_MESSAGE = "This test is disabled"; protected static final String DISABLE_MESSAGE = "This test is disabled";
@@ -40,13 +40,15 @@ public class SensorTest extends ActivityInstrumentationTestCase2<TrackListActivi
private Instrumentation instrumentation; private Instrumentation instrumentation;
private TrackListActivity trackListActivity; private TrackListActivity trackListActivity;
private boolean runTest = false;
private static final String ZEPHYR_NAME = "HXM"; private static final String ZEPHYR_NAME = "HXM";
private static final String POLAR_NAME = "Polar"; private static final String POLAR_NAME = "Polar";
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
runTest = SecondaryTestUtils.runSensorTest;
super.setUp(); super.setUp();
if (!SecondaryTestUtils.runTest) { if (!runTest) {
return; return;
} }
instrumentation = getInstrumentation(); instrumentation = getInstrumentation();
@@ -59,7 +61,7 @@ public class SensorTest extends ActivityInstrumentationTestCase2<TrackListActivi
* sensor must be paired with the device. * sensor must be paired with the device.
*/ */
public void testConnectZephyrBluetoothSensor_notRecording() { public void testConnectZephyrBluetoothSensor_notRecording() {
if (!SecondaryTestUtils.runTest) { if (!runTest) {
Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE); Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE);
return; return;
} }
@@ -71,7 +73,7 @@ public class SensorTest extends ActivityInstrumentationTestCase2<TrackListActivi
* sensor must be paired with the device. * sensor must be paired with the device.
*/ */
public void testConnectZephyrBluetoothSensor_underRecording() { public void testConnectZephyrBluetoothSensor_underRecording() {
if (!SecondaryTestUtils.runTest) { if (!runTest) {
Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE); Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE);
return; return;
} }
@@ -83,7 +85,7 @@ public class SensorTest extends ActivityInstrumentationTestCase2<TrackListActivi
* sensor must be paired with the device. * sensor must be paired with the device.
*/ */
public void testConnectPolarBluetoothSensor_notRecording() { public void testConnectPolarBluetoothSensor_notRecording() {
if (!SecondaryTestUtils.runTest) { if (!runTest) {
Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE); Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE);
return; return;
} }
@@ -95,7 +97,7 @@ public class SensorTest extends ActivityInstrumentationTestCase2<TrackListActivi
* sensor must be paired with the device. * sensor must be paired with the device.
*/ */
public void testConnectPolarBluetoothSensor_underRecording() { public void testConnectPolarBluetoothSensor_underRecording() {
if (!SecondaryTestUtils.runTest) { if (!runTest) {
Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE); Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE);
return; return;
} }
@@ -150,7 +152,7 @@ public class SensorTest extends ActivityInstrumentationTestCase2<TrackListActivi
* Tests connecting to a cadence ANT+ sensor. * Tests connecting to a cadence ANT+ sensor.
*/ */
public void testConnectANTSensor_Cadence() { public void testConnectANTSensor_Cadence() {
if (!SecondaryTestUtils.runTest) { if (!runTest) {
Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE); Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE);
return; return;
} }
@@ -163,7 +165,7 @@ public class SensorTest extends ActivityInstrumentationTestCase2<TrackListActivi
* Tests connecting to cadence and heart rate ANT+ sensors at the same time. * Tests connecting to cadence and heart rate ANT+ sensors at the same time.
*/ */
public void testConnectTwoANTSensors() { public void testConnectTwoANTSensors() {
if (!SecondaryTestUtils.runTest) { if (!runTest) {
Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE); Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE);
return; return;
} }
@@ -232,7 +234,7 @@ public class SensorTest extends ActivityInstrumentationTestCase2<TrackListActivi
@Override @Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
if (!SecondaryTestUtils.runTest) { if (!runTest) {
return; return;
} }
EndToEndTestUtils.SOLO.finishOpenedActivities(); EndToEndTestUtils.SOLO.finishOpenedActivities();
@@ -32,6 +32,8 @@ public class StressTest extends ActivityInstrumentationTestCase2<TrackListActivi
private static final int TEST_DURATION_IN_MILLISECONDS = 30 * 60 * 1000; private static final int TEST_DURATION_IN_MILLISECONDS = 30 * 60 * 1000;
private static final int MAX_TRACK_NUMBER = 30; private static final int MAX_TRACK_NUMBER = 30;
private boolean runTest = false;
private long startTime = 0; private long startTime = 0;
private int numberOfTracks; private int numberOfTracks;
@@ -44,8 +46,9 @@ public class StressTest extends ActivityInstrumentationTestCase2<TrackListActivi
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
runTest = SecondaryTestUtils.runStressTest;
super.setUp(); super.setUp();
if (!SecondaryTestUtils.runTest) { if (!runTest) {
return; return;
} }
instrumentation = getInstrumentation(); instrumentation = getInstrumentation();
@@ -60,7 +63,7 @@ public class StressTest extends ActivityInstrumentationTestCase2<TrackListActivi
* each track, making it closer to the real stress. * each track, making it closer to the real stress.
*/ */
public void testRecordAndDeleteTracks() { public void testRecordAndDeleteTracks() {
if (!SecondaryTestUtils.runTest) { if (!runTest) {
Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE); Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE);
return; return;
} }
@@ -84,7 +87,7 @@ public class StressTest extends ActivityInstrumentationTestCase2<TrackListActivi
* in each track, making it closer to the real stress. * in each track, making it closer to the real stress.
*/ */
public void testRotateMapViewInTrackDetailActivity() { public void testRotateMapViewInTrackDetailActivity() {
if (!SecondaryTestUtils.runTest) { if (!runTest) {
Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE); Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE);
return; return;
} }
@@ -99,7 +102,7 @@ public class StressTest extends ActivityInstrumentationTestCase2<TrackListActivi
* Switches view between MAP, CHART and STAT. * Switches view between MAP, CHART and STAT.
*/ */
public void testSwitchTabs() { public void testSwitchTabs() {
if (!SecondaryTestUtils.runTest) { if (!runTest) {
Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE); Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE);
return; return;
} }
@@ -123,7 +126,7 @@ public class StressTest extends ActivityInstrumentationTestCase2<TrackListActivi
* Switches view between MAP, CHART and STAT. * Switches view between MAP, CHART and STAT.
*/ */
public void testSwitchTabs_wayPoints() { public void testSwitchTabs_wayPoints() {
if (!SecondaryTestUtils.runTest) { if (!runTest) {
Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE); Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE);
return; return;
} }