Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Rework instrumentation tests #8793

Merged
merged 1 commit into from
Apr 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
--app platform/android/MapboxGLAndroidSDKTestApp/build/outputs/apk/MapboxGLAndroidSDKTestApp-debug.apk \
--test platform/android/MapboxGLAndroidSDKTestApp/build/outputs/apk/MapboxGLAndroidSDKTestApp-debug-androidTest.apk \
--device-ids shamu --os-version-ids 22 --locales en --orientations portrait --timeout 15m \
--test-targets "class com.mapbox.mapboxsdk.testapp.maps.widgets.AttributionTest" 2>&1 | tee firebase.log) || EXIT_CODE=$?
--test-targets "class com.mapbox.mapboxsdk.testapp.maps.widgets.LogoTest" 2>&1 | tee firebase.log) || EXIT_CODE=$?
FIREBASE_TEST_BUCKET=$(sed -n 's|^.*\[https://console.developers.google.com/storage/browser/\([^]]*\).*|gs://\1|p' firebase.log)
echo "Downloading from: ${FIREBASE_TEST_BUCKET}"
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
package com.mapbox.mapboxsdk.testapp.activity;

import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.test.espresso.Espresso;
import android.support.test.espresso.IdlingResourceTimeoutException;
import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.support.test.rule.ActivityTestRule;

import timber.log.Timber;
import android.view.View;

import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource;
import com.mapbox.mapboxsdk.testapp.utils.ScreenshotUtil;

import junit.framework.Assert;

import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;

import timber.log.Timber;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
Expand Down Expand Up @@ -46,27 +54,62 @@ public void beforeTest() {
}
}

protected void validateTestSetup() {
Assert.assertTrue("Device is not connected to the Internet.", isConnected(rule.getActivity()));
checkViewIsDisplayed(R.id.mapView);
Assert.assertNotNull(mapboxMap);
}

protected MapboxMap getMapboxMap() {
return mapboxMap;
}

protected abstract Class getActivityClass();

protected void checkViewIsDisplayed(int id) {
onView(withId(id))
.check(matches(isDisplayed()));
}

protected void takeScreenshot(final String name) {
final Activity activity = rule.getActivity();
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
ScreenshotUtil.take(activity, name);
}
});
protected void waitLoop() {
onView(withId(R.id.mapView)).perform(new LoopAction(500));
}

static boolean isConnected(Context context) {
ConnectivityManager connectivityManager
= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}

@After
public void afterTest() {
Timber.e("@After test: unregister idle resource");
Espresso.unregisterIdlingResources(idlingResource);
}

private class LoopAction implements ViewAction {

private long loopTime;

public LoopAction(long loopTime) {
this.loopTime = loopTime;
}

@Override
public Matcher<View> getConstraints() {
return isDisplayed();
}

@Override
public String getDescription() {
return getClass().getSimpleName();
}

@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadForAtLeast(loopTime);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class <%- activity %>Test extends BaseActivityTest {

@Test
public void testSanity() {
onView(withId(R.id.mapView)).check(matches(isDisplayed()));
validateTestSetup();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
package com.mapbox.mapboxsdk.testapp.annotations;

import android.support.test.espresso.Espresso;
import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.support.test.rule.ActivityTestRule;
import android.view.View;

import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource;
import com.mapbox.mapboxsdk.testapp.utils.TestConstants;
import com.mapbox.mapboxsdk.testapp.utils.ViewUtils;

import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;

import static android.support.test.espresso.Espresso.onView;
Expand All @@ -30,25 +24,19 @@
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.junit.Assert.assertEquals;

public class MarkerTest {
public class MarkerTest extends BaseActivityTest {

@Rule
public final ActivityTestRule<EspressoTestActivity> rule = new ActivityTestRule<>(EspressoTestActivity.class);

private OnMapReadyIdlingResource idlingResource;
private Marker marker;

@Before
public void registerIdlingResource() {
idlingResource = new OnMapReadyIdlingResource(rule.getActivity());
Espresso.registerIdlingResources(idlingResource);
@Override
protected Class getActivityClass() {
return EspressoTestActivity.class;
}

@Test
@Ignore
public void addMarkerTest() {
ViewUtils.checkViewIsDisplayed(R.id.mapView);
MapboxMap mapboxMap = rule.getActivity().getMapboxMap();
validateTestSetup();
assertEquals("Markers should be empty", 0, mapboxMap.getMarkers().size());

MarkerOptions options = new MarkerOptions();
Expand All @@ -69,8 +57,7 @@ public void addMarkerTest() {
@Test
@Ignore
public void showInfoWindowTest() {
ViewUtils.checkViewIsDisplayed(R.id.mapView);
MapboxMap mapboxMap = rule.getActivity().getMapboxMap();
validateTestSetup();

final MarkerOptions options = new MarkerOptions();
options.setPosition(new LatLng());
Expand Down Expand Up @@ -133,10 +120,4 @@ public void perform(UiController uiController, View view) {

}
}


@After
public void unregisterIdlingResource() {
Espresso.unregisterIdlingResources(idlingResource);
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
package com.mapbox.mapboxsdk.testapp.annotations;

import android.support.test.espresso.Espresso;
import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.support.test.rule.ActivityTestRule;
import android.view.View;

import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.annotation.MarkerViewActivity;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import com.mapbox.mapboxsdk.testapp.model.annotations.TextMarkerViewOptions;
import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource;
import com.mapbox.mapboxsdk.testapp.utils.TestConstants;
import com.mapbox.mapboxsdk.testapp.utils.ViewUtils;

import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;

import static android.support.test.espresso.Espresso.onView;
Expand All @@ -31,25 +25,19 @@
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.junit.Assert.assertEquals;

public class MarkerViewTest {
public class MarkerViewTest extends BaseActivityTest {

@Rule
public final ActivityTestRule<EspressoTestActivity> rule = new ActivityTestRule<>(EspressoTestActivity.class);

private OnMapReadyIdlingResource idlingResource;
private Marker marker;

@Before
public void registerIdlingResource() {
idlingResource = new OnMapReadyIdlingResource(rule.getActivity());
Espresso.registerIdlingResources(idlingResource);
@Override
protected Class getActivityClass() {
return EspressoTestActivity.class;
}

@Test
@Ignore
public void addMarkerViewTest() {
ViewUtils.checkViewIsDisplayed(R.id.mapView);
MapboxMap mapboxMap = rule.getActivity().getMapboxMap();
validateTestSetup();
assertEquals("Markers should be empty", 0, mapboxMap.getMarkers().size());

TextMarkerViewOptions options = new TextMarkerViewOptions();
Expand All @@ -70,8 +58,7 @@ public void addMarkerViewTest() {
@Test
@Ignore
public void showInfoWindowTest() {
ViewUtils.checkViewIsDisplayed(R.id.mapView);
MapboxMap mapboxMap = rule.getActivity().getMapboxMap();
validateTestSetup();

final TextMarkerViewOptions options = new TextMarkerViewOptions();
options.position(new LatLng());
Expand Down Expand Up @@ -139,9 +126,4 @@ public void perform(UiController uiController, View view) {
uiController.loopMainThreadForAtLeast(250);
}
}

@After
public void unregisterIdlingResource() {
Espresso.unregisterIdlingResources(idlingResource);
}
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,41 @@
package com.mapbox.mapboxsdk.testapp.annotations;

import android.graphics.Color;
import android.support.test.espresso.Espresso;
import android.support.test.espresso.UiController;
import android.support.test.espresso.ViewAction;
import android.support.test.rule.ActivityTestRule;
import android.view.View;

import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource;
import com.mapbox.mapboxsdk.testapp.utils.ViewUtils;

import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.junit.Assert.assertEquals;

public class PolygonTest {
public class PolygonTest extends BaseActivityTest {

@Rule
public final ActivityTestRule<EspressoTestActivity> rule = new ActivityTestRule<>(EspressoTestActivity.class);
@Override
protected Class getActivityClass() {
return EspressoTestActivity.class;
}

private OnMapReadyIdlingResource idlingResource;
private Polygon polygon;

@Before
public void registerIdlingResource() {
idlingResource = new OnMapReadyIdlingResource(rule.getActivity());
Espresso.registerIdlingResources(idlingResource);
}

@Test
@Ignore
/** native crash **/
public void addPolygonTest() {
ViewUtils.checkViewIsDisplayed(R.id.mapView);
final MapboxMap mapboxMap = rule.getActivity().getMapboxMap();
validateTestSetup();
LatLng latLngOne = new LatLng();
LatLng latLngTwo = new LatLng(1, 0);
LatLng latLngThree = new LatLng(1, 1);
Expand Down Expand Up @@ -97,9 +85,4 @@ public void perform(UiController uiController, View view) {
polygon = mapboxMap.addPolygon(options);
}
}

@After
public void unregisterIdlingResource() {
Espresso.unregisterIdlingResources(idlingResource);
}
}
Loading