Add a stress test case. Switch views when track has mwrkers.

This commit is contained in:
youtaol
2012-12-03 22:06:47 +08:00
parent 3711a97fc3
commit db3194224b
4 changed files with 68 additions and 26 deletions
@@ -32,7 +32,6 @@ import java.util.ArrayList;
*/
public class CreateTrackTest extends ActivityInstrumentationTestCase2<TrackListActivity> {
private static final String WAYPOINT_NAME = "testWaypoint";
private Instrumentation instrumentation;
private TrackListActivity activityMyTracks;
@@ -126,7 +125,7 @@ public class CreateTrackTest extends ActivityInstrumentationTestCase2<TrackListA
.getString(R.string.generic_recording)));
}
createWaypoint();
EndToEndTestUtils.createWaypoint(0);
EndToEndTestUtils.sendGps(2, 2);
// Back to tracks list.
EndToEndTestUtils.SOLO.goBack();
@@ -206,23 +205,6 @@ public class CreateTrackTest extends ActivityInstrumentationTestCase2<TrackListA
EndToEndTestUtils.stopRecording(true);
}
/**
* Creates a way point and a split maker during track recording.
*/
private void createWaypoint() {
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_markers), true);
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.marker_list_empty_message)));
EndToEndTestUtils.findMenuItem(activityMyTracks.getString(R.string.menu_insert_marker), true);
EndToEndTestUtils.enterTextAvoidSoftKeyBoard(0, WAYPOINT_NAME);
EndToEndTestUtils.SOLO.clickOnButton(activityMyTracks.getString(R.string.generic_add));
if (EndToEndTestUtils.hasGpsSingal) {
assertTrue(EndToEndTestUtils.SOLO.waitForText(WAYPOINT_NAME, 1, EndToEndTestUtils.LONG_WAIT_TIME, true));
} else {
assertFalse(EndToEndTestUtils.SOLO.searchText(WAYPOINT_NAME));
}
EndToEndTestUtils.SOLO.goBack();
}
@Override
protected void tearDown() throws Exception {
@@ -66,6 +66,7 @@ public class EndToEndTestUtils {
static final double START_LATITUDE = -1.3f;
static final double DELTA_LONGITUDE = 0.0005f;
static final double DELTA_LADITUDE = 0.0005f;
private static final String WAYPOINT_NAME = "testWaypoint";
private static final String NO_GPS_MESSAGE_PREFIX = "GPS is not available";
private static final String MOREOPTION_CLASSNAME = "com.android.internal.view.menu.ActionMenuPresenter$OverflowMenuButton";
@@ -250,6 +251,9 @@ public class EndToEndTestUtils {
EndToEndTestUtils.instrumentation = instrumentation;
EndToEndTestUtils.activityMytracks = activityMyTracks;
SOLO = new Solo(EndToEndTestUtils.instrumentation, EndToEndTestUtils.activityMytracks);
setIsEmulator();
hasActionBar = setHasActionBar();
checkLanguage();
}
/**
@@ -280,7 +284,7 @@ public class EndToEndTestUtils {
Log.e(LOG_TAG, "Need update Google Play Services");
}
setIsEmulator();
if ((getButtonOnScreen(EndToEndTestUtils.activityMytracks.getString(R.string.eula_accept),
if ((getButtonOnScreen(activityMytracks.getString(R.string.eula_accept),
false, false) != null)) {
verifyFirstLaunch();
} else if (SOLO.waitForText(
@@ -299,7 +303,7 @@ public class EndToEndTestUtils {
if (!isEmulator) {
GoToMyLocationTest.findAndClickMyLocation(activityMyTracks);
hasGpsSingal = !SOLO.waitForText(NO_GPS_MESSAGE_PREFIX, 1,
EndToEndTestUtils.SHORT_WAIT_TIME);
SHORT_WAIT_TIME);
SOLO.goBack();
}
} else if (SOLO.waitForText(
@@ -730,7 +734,7 @@ public class EndToEndTestUtils {
* Finds the more option menu. It should match following conditions:
* <ul>
* <li>The view extends ImageButton.</li>
* <li>The view name equals {@link EndToEndTestUtils#MOREOPTION_CLASSNAME}.</li>
* <li>The view name equals {@link #MOREOPTION_CLASSNAME}.</li>
* </ul>
* @return the more option view. Null means can not find it.
*/
@@ -935,5 +939,31 @@ public class EndToEndTestUtils {
.findViewById(R.id.track_controller_total_time)).getText().toString();
Assert.assertTrue(totalTimeOld.equalsIgnoreCase(totalTimeNew));
}
/**
* Creates a way point and a split maker during track recording.
*
* @param markerNumber of number of previous markers
*/
public static void createWaypoint(int markerNumber) {
findMenuItem(activityMytracks.getString(R.string.menu_markers), true);
if (markerNumber > 0) {
int actualMarkerNumber = SOLO.getCurrentListViews().get(0).getCount();
Assert.assertEquals(markerNumber, actualMarkerNumber);
} else {
Assert.assertTrue(SOLO.waitForText(activityMytracks
.getString(R.string.marker_list_empty_message)));
}
findMenuItem(activityMytracks.getString(R.string.menu_insert_marker), true);
enterTextAvoidSoftKeyBoard(0, WAYPOINT_NAME);
SOLO.clickOnButton(activityMytracks.getString(R.string.generic_add));
if (hasGpsSingal) {
Assert.assertTrue(SOLO.waitForText(WAYPOINT_NAME, 1, LONG_WAIT_TIME, true));
} else {
Assert.assertFalse(SOLO.searchText(WAYPOINT_NAME));
}
SOLO.goBack();
}
}
@@ -6,7 +6,7 @@ public class SecondaryTestUtils {
* Set to false as default. True to run the test. Default to false since this
* test can take a long time.
*/
protected static boolean runTest = false;
protected static boolean runTest = true;
protected static final String DISABLE_MESSAGE = "This test is disabled";
@@ -52,7 +52,6 @@ public class StressTest extends ActivityInstrumentationTestCase2<TrackListActivi
trackListActivity = getActivity();
EndToEndTestUtils.setupForAllTest(instrumentation, trackListActivity);
startTime = System.currentTimeMillis();
EndToEndTestUtils.emulatorPort = 5568;
}
/**
@@ -120,15 +119,46 @@ public class StressTest extends ActivityInstrumentationTestCase2<TrackListActivi
}
}
/**
* Switches view between MAP, CHART and STAT.
*/
public void testSwitchTabs_wayPoints() {
if (!SecondaryTestUtils.runTest) {
Log.i(EndToEndTestUtils.LOG_TAG, SecondaryTestUtils.DISABLE_MESSAGE);
return;
}
EndToEndTestUtils.startRecording();
int i = 0;
while ((System.currentTimeMillis() - startTime) < TEST_DURATION_IN_MILLISECONDS) {
// Create one way points.
EndToEndTestUtils.sendGps(10, 10 * i);
EndToEndTestUtils.createWaypoint(i);
EndToEndTestUtils.pauseRecording();
EndToEndTestUtils.SOLO
.clickOnText(trackListActivity.getString(R.string.track_detail_map_tab));
instrumentation.waitForIdleSync();
EndToEndTestUtils.SOLO.clickOnText(trackListActivity
.getString(R.string.track_detail_chart_tab));
instrumentation.waitForIdleSync();
EndToEndTestUtils.SOLO.clickOnText(trackListActivity
.getString(R.string.track_detail_stats_tab));
instrumentation.waitForIdleSync();
EndToEndTestUtils.resumeRecording();
logStatus(++i);
}
}
/**
* Logs status.
*
* @param times the number of times this test has been run
*/
private void logStatus(int times) {
int minutes = (int)(TEST_DURATION_IN_MILLISECONDS - (System.currentTimeMillis() - startTime)) / 60 / 1000;
Log.i(EndToEndTestUtils.LOG_TAG, String.format(
"This test has run d% times and will be finished in d% millis seconds!", times,
TEST_DURATION_IN_MILLISECONDS - (System.currentTimeMillis() - startTime)));
"This test has run %d times and will be finished in %d minutes!", times, minutes));
Log.i(EndToEndTestUtils.LOG_TAG, String.format("There are %d tracks!", numberOfTracks));
}
}