From eefbb754d0ef98af39f9b2dac8dc0a471dc41d27 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Wed, 28 Dec 2016 15:16:18 +0100 Subject: [android] - build and test wear module on CI, cleanup gradle file, added make target, added unit test (#7534) --- .../MapboxGLAndroidSDKWearTestApp/build.gradle | 24 ++++++++++++++----- .../weartestapp/utils/OffsettingHelperTest.java | 28 ++++++++++++++++++++++ platform/android/bitrise.yml | 12 ++++++++-- 3 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 platform/android/MapboxGLAndroidSDKWearTestApp/src/test/java/com/mapbox/weartestapp/utils/OffsettingHelperTest.java (limited to 'platform') diff --git a/platform/android/MapboxGLAndroidSDKWearTestApp/build.gradle b/platform/android/MapboxGLAndroidSDKWearTestApp/build.gradle index 29056e7685..04dd0e7c09 100644 --- a/platform/android/MapboxGLAndroidSDKWearTestApp/build.gradle +++ b/platform/android/MapboxGLAndroidSDKWearTestApp/build.gradle @@ -1,8 +1,13 @@ apply plugin: 'com.android.application' +ext { + wearableVersion = '2.0.0-alpha3' + leakCanaryVersion = '1.5' +} + android { compileSdkVersion 25 - buildToolsVersion "25.0.0" + buildToolsVersion "25.0.1" defaultConfig { applicationId "com.mapbox.mapboxsdk.testapp" @@ -13,6 +18,9 @@ android { } buildTypes { + debug { + testCoverageEnabled = true + } release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' @@ -27,13 +35,17 @@ dependencies { // Wear compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.google.android.support:wearable:2.0.0-alpha3' - provided 'com.google.android.wearable:wearable:2.0.0-alpha3' + compile "com.google.android.support:wearable:${wearableVersion}" + provided "com.google.android.wearable:wearable:${wearableVersion}" // Leak Canary - debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5' - releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5' - testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5' + debugCompile "com.squareup.leakcanary:leakcanary-android:${leakCanaryVersion}" + releaseCompile "com.squareup.leakcanary:leakcanary-android-no-op:${leakCanaryVersion}" + testCompile "com.squareup.leakcanary:leakcanary-android-no-op:${leakCanaryVersion}" + + // Testing dependencies + testCompile 'junit:junit:4.12' + testCompile 'org.mockito:mockito-core:2.2.27' } apply from: 'gradle-config.gradle' diff --git a/platform/android/MapboxGLAndroidSDKWearTestApp/src/test/java/com/mapbox/weartestapp/utils/OffsettingHelperTest.java b/platform/android/MapboxGLAndroidSDKWearTestApp/src/test/java/com/mapbox/weartestapp/utils/OffsettingHelperTest.java new file mode 100644 index 0000000000..aab7714947 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKWearTestApp/src/test/java/com/mapbox/weartestapp/utils/OffsettingHelperTest.java @@ -0,0 +1,28 @@ +package com.mapbox.weartestapp.utils; + +import android.view.View; + +import org.junit.Test; +import org.mockito.InjectMocks; + +import static junit.framework.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class OffsettingHelperTest { + + private static final double DELTA = 1e-15; + + @InjectMocks + View view = mock(View.class); + + @Test + public void testAnchorOffset() { + float[] offset = new float[2]; + int viewHeight = 50; + when(view.getHeight()).thenReturn(viewHeight); + OffsettingHelper offsettingHelper = new OffsettingHelper(); + offsettingHelper.adjustAnchorOffsetXY(view, offset); + assertEquals("Offset of " + viewHeight + " should be divided by 2: ", viewHeight / 2, offset[0], DELTA); + } +} diff --git a/platform/android/bitrise.yml b/platform/android/bitrise.yml index 90723e57a2..d0be8c015f 100644 --- a/platform/android/bitrise.yml +++ b/platform/android/bitrise.yml @@ -83,13 +83,21 @@ workflows: echo "Compiling core tests:" BUILDTYPE=Debug make android-test-lib-arm-v7 - script: - title: Run local JVM Unit tests + title: Run local JVM Unit tests on phone module run_if: '{{enveq "SKIPCI" "false"}}' inputs: - content: |- #!/bin/bash - echo "Running unit tests from testapp/src/test:" + echo "Running unit tests from MapboxGLAndroidSDKTestApp/src/test:" make run-android-unit-test + - script: + title: Run local JVM Unit tests on wear module + run_if: '{{enveq "SKIPCI" "false"}}' + inputs: + - content: |- + #!/bin/bash + echo "Running unit tests from MapboxGLAndroidSDKWearTestApp/src/test:" + make run-android-wear-unit-test - script: title: Generate Espresso sanity tests run_if: '{{enveq "SKIPCI" "false"}}' -- cgit v1.2.1