[android] #4301 - added robotium testing framework to perform integration testing

This commit is contained in:
Tobrun
2016-03-14 11:17:27 -04:00
parent fc0a0ef98a
commit 55a1bb8365
35 changed files with 232 additions and 44 deletions

View File

@@ -63,7 +63,7 @@ android {
}
buildTypes {
debug{
debug {
// run code coverage reports
testCoverageEnabled = true
}
@@ -90,13 +90,13 @@ dependencies {
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
// Directions SDK
compile ('com.mapbox.mapboxsdk:mapbox-android-directions:1.0.0@aar'){
transitive=true
compile('com.mapbox.mapboxsdk:mapbox-android-directions:1.0.0@aar') {
transitive = true
}
// Geocoder SDK
compile ('com.mapbox.mapboxsdk:mapbox-android-geocoder:1.0.0@aar'){
transitive=true
compile('com.mapbox.mapboxsdk:mapbox-android-geocoder:1.0.0@aar') {
transitive = true
}
// Testing dependencies
@@ -106,6 +106,7 @@ dependencies {
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.5.4'
}
checkstyle {

View File

@@ -0,0 +1,18 @@
package com.mapbox.mapboxsdk.maps;
/**
* Utility class to fetch a MapboxMap instance by bypassing package visibility
*/
public class MapboxMapUtils {
/**
* Get the MapboxMap instance linked to passed MapView
*
* @param mapView
* @return
*/
public static MapboxMap getMapboxMap(MapView mapView){
return mapView.getMapboxMap();
}
}

View File

@@ -1,8 +1,8 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.app.Activity;
import com.mapbox.mapboxsdk.testapp.utils.ScreenshotUtil;
import com.mapbox.mapboxsdk.testapp.espresso.utils.ScreenshotUtil;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;

View File

@@ -1,9 +1,12 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.BulkMarkerActivity;
import com.mapbox.mapboxsdk.testapp.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,10 +1,13 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.app.Activity;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.CameraActivity;
import com.mapbox.mapboxsdk.testapp.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,10 +1,13 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.app.Activity;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.CoordinateChangeActivity;
import com.mapbox.mapboxsdk.testapp.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,10 +1,13 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.app.Activity;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.DirectionsActivity;
import com.mapbox.mapboxsdk.testapp.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,10 +1,13 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.app.Activity;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.DoubleMapActivity;
import com.mapbox.mapboxsdk.testapp.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,10 +1,12 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.utils.ViewUtils;
import com.mapbox.mapboxsdk.testapp.DynamicMarkerChangeActivity;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.espresso.utils.ViewUtils;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,10 +1,13 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.app.Activity;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.GeocoderActivity;
import com.mapbox.mapboxsdk.testapp.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,9 +1,12 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.InfoWindowActivity;
import com.mapbox.mapboxsdk.testapp.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,9 +1,12 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.InfoWindowAdapterActivity;
import com.mapbox.mapboxsdk.testapp.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,10 +1,13 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.app.Activity;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.InfoWindowConcurrentActivity;
import com.mapbox.mapboxsdk.testapp.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,9 +1,12 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.LatLngBoundsActivity;
import com.mapbox.mapboxsdk.testapp.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,20 +1,19 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.utils.DrawerUtils;
import com.mapbox.mapboxsdk.testapp.utils.GestureUtils;
import com.mapbox.mapboxsdk.testapp.utils.ScreenshotUtil;
import com.mapbox.mapboxsdk.testapp.MainActivity;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.espresso.utils.DrawerUtils;
import com.mapbox.mapboxsdk.testapp.espresso.utils.GestureUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.doubleClick;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
/**

View File

@@ -1,9 +1,12 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.MainActivity;
import com.mapbox.mapboxsdk.testapp.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,10 +1,13 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.app.Activity;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.ManualZoomActivity;
import com.mapbox.mapboxsdk.testapp.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,9 +1,12 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.MapFragmentActivity;
import com.mapbox.mapboxsdk.testapp.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,10 +1,13 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.app.Activity;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.MapPaddingActivity;
import com.mapbox.mapboxsdk.testapp.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,10 +1,13 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.app.Activity;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.MapboxMapActivity;
import com.mapbox.mapboxsdk.testapp.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,10 +1,13 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.app.Activity;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.MaxMinZoomActivity;
import com.mapbox.mapboxsdk.testapp.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,9 +1,12 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.MyLocationTrackingModeActivity;
import com.mapbox.mapboxsdk.testapp.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,9 +1,12 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.PolylineActivity;
import com.mapbox.mapboxsdk.testapp.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,9 +1,12 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.PressForMarkerActivity;
import com.mapbox.mapboxsdk.testapp.R;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,9 +1,12 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.ScrollByActivity;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@@ -1,10 +1,13 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.app.Activity;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.SupportMapFragmentActivity;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,7 +1,10 @@
package com.mapbox.mapboxsdk.testapp;
package com.mapbox.mapboxsdk.testapp.espresso;
import android.support.test.rule.ActivityTestRule;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.TiltActivity;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

View File

@@ -1,4 +1,4 @@
package com.mapbox.mapboxsdk.testapp.utils;
package com.mapbox.mapboxsdk.testapp.espresso.utils;
import android.support.annotation.StringRes;
import android.support.test.espresso.Espresso;

View File

@@ -1,9 +1,7 @@
package com.mapbox.mapboxsdk.testapp.utils;
package com.mapbox.mapboxsdk.testapp.espresso.utils;
import android.support.annotation.IdRes;
import com.mapbox.mapboxsdk.testapp.R;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.doubleClick;
import static android.support.test.espresso.matcher.ViewMatchers.withId;

View File

@@ -1,4 +1,4 @@
package com.mapbox.mapboxsdk.testapp.utils;
package com.mapbox.mapboxsdk.testapp.espresso.utils;
import android.app.Activity;
import android.graphics.Bitmap;

View File

@@ -1,4 +1,4 @@
package com.mapbox.mapboxsdk.testapp.utils;
package com.mapbox.mapboxsdk.testapp.espresso.utils;
import android.support.annotation.IdRes;

View File

@@ -0,0 +1,42 @@
package com.mapbox.mapboxsdk.testapp.robotium;
import android.test.ActivityInstrumentationTestCase2;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.MapboxMapUtils;
import com.mapbox.mapboxsdk.testapp.MainActivity;
import com.mapbox.mapboxsdk.testapp.R;
import com.robotium.solo.Solo;
import org.junit.Test;
public abstract class BaseMainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {
protected Solo solo;
protected MapView mapView;
protected MapboxMap mapboxMap;
public BaseMainActivityTest() {
super(MainActivity.class);
}
@Override
public void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
mapView = (MapView) solo.getView(R.id.mainMapView);
mapboxMap = MapboxMapUtils.getMapboxMap(mapView);
}
@Override
public void tearDown() throws Exception {
solo.finishOpenedActivities();
}
@Test
public void testSanity() throws Exception {
assertNotNull("Should be non null", solo);
assertNotNull("Should be non null", mapView);
assertNotNull("Should be non null", mapboxMap);
}
}

View File

@@ -0,0 +1,46 @@
package com.mapbox.mapboxsdk.testapp.robotium;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.widgets.CompassView;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.robotium.utils.ViewAssertion;
import org.junit.Test;
public class CompassViewTest extends BaseMainActivityTest {
private CompassView compassView;
@Override
public void setUp() throws Exception {
super.setUp();
compassView = (CompassView) solo.getView(R.id.compassView);
}
@Test
public void testCompass() {
setCameraDirection(0);
solo.sleep(200);
ViewAssertion.isInvisible(compassView);
}
@Test
public void testCompassClick() throws Exception {
setCameraDirection(20);
solo.sleep(200);
ViewAssertion.isVisible(compassView);
solo.clickOnView(compassView);
solo.sleep(200);
ViewAssertion.isVisible(compassView);
}
private void setCameraDirection(float bearing) {
mapboxMap.setCameraPosition(new CameraPosition.Builder()
.target(new LatLng(0, 0))
.tilt(0)
.zoom(15)
.bearing(bearing)
.build());
}
}

View File

@@ -0,0 +1,17 @@
package com.mapbox.mapboxsdk.testapp.robotium.utils;
import android.view.View;
import static junit.framework.Assert.assertEquals;
public class ViewAssertion {
public static void isVisible(View view) {
assertEquals(view.getClass().getSimpleName() + " should be visible", view.getVisibility(), View.VISIBLE);
}
public static void isInvisible(View view) {
assertEquals(view.getClass().getSimpleName() + " should be visible", view.getVisibility(), View.INVISIBLE);
}
}

View File

@@ -4,7 +4,6 @@ import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.mapbox.mapboxsdk.constants.MapboxConstants;