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

5859 generate sanity tests #5870

Merged
merged 7 commits into from
Aug 17, 2016
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ apackage:
style-code-android:
node platform/android/scripts/generate-style-code.js

.PHONY: android-generate-test
android-generate-test:
node platform/android/scripts/generate-test-code.js

#### Miscellaneous targets #####################################################

.PHONY: style-code
Expand Down
4 changes: 4 additions & 0 deletions platform/android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ fabric.properties

# Capture files
captures/

# Generated test cases
MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/activity/gen/

41 changes: 41 additions & 0 deletions platform/android/MapboxGLAndroidSDKTestApp/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'
apply plugin: 'checkstyle'
apply plugin: 'devicefarm'

task accessToken {
def tokenFile = new File("MapboxGLAndroidSDKTestApp/src/main/res/values/developer-config.xml")
Expand Down Expand Up @@ -109,6 +110,46 @@ checkstyle {
showViolations true
}


def getAccessKeyDeviceFarm() {
return hasProperty('AWS_ACCESS_KEY_ID_DEVICE_FARM') ? AWS_ACCESS_KEY_ID_DEVICE_FARM : ""
}

def getSecretAccessKeyDeviceFarm() {
return hasProperty('AWS_SECRET_ACCESS_KEY_DEVICE_FARM') ? AWS_SECRET_ACCESS_KEY_DEVICE_FARM : ""
}

devicefarm {

projectName "Mapbox GL Android" // required: Must already exists.
devicePool "sanity" // optional: Defaults to "Top Devices"

authentication {
accessKey getAccessKeyDeviceFarm()
secretKey getSecretAccessKeyDeviceFarm()
}

// optional block, radios default to 'on' state, all parameters optional
devicestate {
///extraDataZipFile file("path/to/zip") // or ‘null’ if you have no extra data. Default is null.
//auxiliaryApps files(file("path/to/app"), file("path/to/app2")) // or ‘files()’ if you have no auxiliary apps. Default is an empty list.
wifi "on"
bluetooth "off"
gps "on"
nfc "on"
latitude 47.6204 // default
longitude - 122.3491 // default
}

// Instrumentation
// optional filter "my-filter"
// See AWS Developer docs
instrumentation {

}
}


android.applicationVariants.all { variant ->
def name = variant.buildType.name
def checkstyle = project.tasks.create "checkstyle${name.capitalize()}", Checkstyle
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,44 +1,62 @@
package com.mapbox.mapboxsdk.activity;

import android.app.Activity;
import android.support.test.espresso.Espresso;
import android.support.test.rule.ActivityTestRule;
import android.util.Log;

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

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

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;

/**
* Base Espresso class for all tests, helps working with ActivityInstrumentationTestCase2
*/
public class BaseTest {
public abstract class BaseTest {

@Rule
public ActivityTestRule<Activity> rule = new ActivityTestRule<>(getActivityClass());
protected MapboxMap mapboxMap;
protected OnMapReadyIdlingResource idlingResource;

protected final static String HOME_BUTTON_STRING = "Navigate up";
@Before
public void beforeTest() {
Log.e(MapboxConstants.TAG, "@Before test: register idle resource");
idlingResource = new OnMapReadyIdlingResource(rule.getActivity());
Espresso.registerIdlingResources(idlingResource);
checkViewIsDisplayed(R.id.mapView);
mapboxMap = idlingResource.getMapboxMap();
}

/*
* Shortcuts for common UI tests
*/
protected abstract Class getActivityClass();

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

/*
* Screenshots logic
*/

protected void takeNamedScreenshot(final Activity activity, final String name) {

// Screenshots need to be taken on the UI thread
protected void takeScreenshot(final String name) {
final Activity activity = rule.getActivity();
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
ScreenshotUtil.take(activity, name);
}
});

}

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

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading