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

Commit

Permalink
[android] - Render tests with PixelMatch
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Sep 22, 2017
1 parent c9cb4ef commit 2477cc6
Show file tree
Hide file tree
Showing 20 changed files with 491 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,17 @@ run-android-ui-test-$1-%: platform/android/configuration.gradle
-adb uninstall com.mapbox.mapboxsdk.testapp 2> /dev/null
cd platform/android && $(MBGL_ANDROID_GRADLE) -Pmapbox.abis=$2 :MapboxGLAndroidSDKTestApp:connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class="$$*"

# Run render tests with pixelmatch
.PHONY: run-android-render-test-$1
run-android-render-test-$1: platform/android/configuration.gradle
-adb uninstall com.mapbox.mapboxsdk.testapp 2> /dev/null
# run RenderTest.java to generate static map images
cd platform/android && $(MBGL_ANDROID_GRADLE) -Pmapbox.abis=$2 :MapboxGLAndroidSDKTestApp:connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class="com.mapbox.mapboxsdk.testapp.render.RenderTest"
# pull generated images from the device
adb pull "`adb shell 'printenv EXTERNAL_STORAGE' | tr -d '\r'`/mapbox" platform/android/build/render-test
# copy expected result and run pixelmatch
python platform/android/scripts/run-render-test.py

endef

# Explodes the arguments into individual variables
Expand Down Expand Up @@ -641,6 +652,11 @@ android-lint-test-app: platform/android/configuration.gradle
android-javadoc: platform/android/configuration.gradle
cd platform/android && $(MBGL_ANDROID_GRADLE) -Pmapbox.abis=none :MapboxGLAndroidSDK:javadocrelease

# Update render tests
,PHONY: update-android-render-test
update-android-render-test:
python platform/android/scripts/update-render-expected.py

# Open Android Studio if machine is macos
ifeq ($(HOST_PLATFORM), macos)
.PHONY: aproj
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.mapbox.mapboxsdk.testapp.render;

import android.support.test.espresso.Espresso;

import android.support.test.espresso.IdlingPolicies;
import android.support.test.espresso.IdlingResourceTimeoutException;

import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import com.mapbox.mapboxsdk.testapp.activity.render.RenderTestActivity;
import com.mapbox.mapboxsdk.testapp.utils.SnapshotterIdlingResource;

import junit.framework.Assert;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.concurrent.TimeUnit;

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;
import static android.support.test.espresso.matcher.ViewMatchers.withId;

/**
* Instrumentation render tests
*/
@RunWith(AndroidJUnit4.class)
public class RenderTest {

private SnapshotterIdlingResource idlingResource;

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

@Before
public void beforeTest() {
try {
Timber.e("@Before test: register idle resource");
IdlingPolicies.setIdlingResourceTimeout(2, TimeUnit.MINUTES);
Espresso.registerIdlingResources(idlingResource = new SnapshotterIdlingResource(rule.getActivity()));
} catch (IdlingResourceTimeoutException idlingResourceTimeoutException) {
throw new RuntimeException("Idling out!");
}
}

@Test
public void testRender() {
onView(withId(android.R.id.content)).check(matches(isDisplayed()));
Assert.assertTrue(rule.getActivity().isFinishedRendering());
}

@After
public void afterTest() {
Timber.e("@After test: unregister idle resource");
Espresso.unregisterIdlingResources(idlingResource);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.mapbox.mapboxsdk.testapp.utils;

import android.support.test.espresso.IdlingResource;

import com.mapbox.mapboxsdk.testapp.activity.render.RenderTestActivity;

public class SnapshotterIdlingResource implements IdlingResource {

private final RenderTestActivity activity;
private IdlingResource.ResourceCallback resourceCallback;

public SnapshotterIdlingResource(RenderTestActivity activity) {
this.activity = activity;
}

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

@Override
public boolean isIdleNow() {
boolean idle = isSnapshotReady();
if (idle && resourceCallback != null) {
resourceCallback.onTransitionToIdle();
}
return idle;
}

@Override
public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
this.resourceCallback = resourceCallback;
}

private boolean isSnapshotReady() {
return activity != null && activity.isFinishedRendering();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,9 @@
<activity
android:name=".activity.style.FillExtrusionStyleTestActivity"
android:screenOrientation="portrait"/>
<activity
android:name=".activity.render.RenderTestActivity"
android:screenOrientation="portrait"/>
<!-- Configuration Settings -->
<meta-data
android:name="com.mapbox.TestEventsServer"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
[
{
"name": "World",
"width": 512,
"height": 512,
"center": [
0,
0
],
"zoom": 0,
"tilt": 0,
"bearing": 0,
"styleUrl": "mapbox://styles/mapbox/streets-v10"
},
{
"name": "Brussels",
"width": 512,
"height": 512,
"center": [
50.846728,
4.352429
],
"zoom": 12,
"tilt": 0,
"bearing": 0,
"styleUrl": "mapbox://styles/mapbox/streets-v10"
},
{
"name": "San Francisco",
"width": 512,
"height": 512,
"center": [
37.772544,
-122.426622
],
"zoom": 9,
"tilt": 60,
"bearing": 0,
"styleUrl": "mapbox://styles/mapbox/streets-v10"
},
{
"name": "Washington DC",
"width": 512,
"height": 512,
"center": [
38.897717,
-77.036035
],
"zoom": 18,
"tilt": 20,
"bearing": 180,
"styleUrl": "mapbox://styles/mapbox/streets-v10"
},
{
"name": "Ayacucho",
"width": 512,
"height": 512,
"center": [
-13.164131,
-74.220973
],
"zoom": 12,
"tilt": 30,
"bearing": 270,
"styleUrl": "mapbox://styles/mapbox/streets-v10"
},
{
"name": "Bangalore",
"width": 512,
"height": 512,
"center": [
12.970020,
77.590421
],
"zoom": 14,
"tilt": 0,
"bearing": 0,
"styleUrl": "mapbox://styles/mapbox/streets-v10"
},
{
"name": "Berlin",
"width": 512,
"height": 512,
"center": [
52.519716,
13.402068
],
"zoom": 12,
"tilt": 0,
"bearing": 0,
"styleUrl": "mapbox://styles/mapbox/streets-v10"
},
{
"name": "Lisbon",
"width": 512,
"height": 512,
"center": [
38.722062,
-9.138746
],
"zoom": 15,
"tilt": 45,
"bearing": 90,
"styleUrl": "mapbox://styles/mapbox/outdoors-v10"
},
{
"name": "Helsinki",
"width": 512,
"height": 512,
"center": [
60.171283,
24.933533
],
"zoom": 12,
"tilt": 0,
"bearing": 0,
"styleUrl": "mapbox://styles/mapbox/streets-v10"
},
{
"name": "Madrid",
"width": 512,
"height": 512,
"center": [
40.417025,
-3.705287
],
"zoom": 16,
"tilt": 35,
"bearing": 0,
"styleUrl": "mapbox://styles/mapbox/light-v9"
},
{
"name": "London",
"width": 512,
"height": 512,
"center": [
51.508049,
-0.129756
],
"zoom": 12,
"tilt": 0,
"bearing": 0,
"styleUrl": "mapbox://styles/mapbox/dark-v9"
}
]
Loading

0 comments on commit 2477cc6

Please sign in to comment.