Explorar el Código

upgrade gradle, robolectric, fixed unit tests

Daniel Zlotin hace 6 años
padre
commit
61d21c3225

+ 1
- 1
lib/android/app/build.gradle Ver fichero

@@ -56,7 +56,7 @@ dependencies {
56 56
 
57 57
     // tests
58 58
     testCompile 'junit:junit:4.12'
59
-    testCompile 'org.robolectric:robolectric:3.3'
59
+    testCompile 'org.robolectric:robolectric:3.5.1'
60 60
     testCompile 'org.assertj:assertj-core:2.5.0'
61 61
     testCompile 'com.squareup.assertj:assertj-android:1.1.1'
62 62
     testCompile 'org.mockito:mockito-core:2.7.5'

+ 0
- 8
lib/android/app/src/test/AndroidManifest.xml Ver fichero

@@ -1,8 +0,0 @@
1
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
-          package="com.reactnativenavigation">
3
-
4
-    <application
5
-        android:name=".TestApplication"
6
-        android:theme="@style/Theme.AppCompat.Light">
7
-    </application>
8
-</manifest>

+ 10
- 12
lib/android/app/src/test/java/com/reactnativenavigation/BaseTest.java Ver fichero

@@ -1,20 +1,18 @@
1 1
 package com.reactnativenavigation;
2 2
 
3
-import android.app.Activity;
4
-import android.view.View;
5
-import android.view.ViewGroup;
3
+import android.app.*;
4
+import android.support.v7.app.*;
5
+import android.view.*;
6 6
 
7
-import org.junit.After;
8
-import org.junit.Before;
9
-import org.junit.runner.RunWith;
10
-import org.robolectric.Robolectric;
11
-import org.robolectric.RobolectricTestRunner;
12
-import org.robolectric.annotation.Config;
7
+import org.junit.*;
8
+import org.junit.runner.*;
9
+import org.robolectric.*;
10
+import org.robolectric.annotation.*;
13 11
 
14
-import static org.assertj.core.api.Java6Assertions.assertThat;
12
+import static org.assertj.core.api.Java6Assertions.*;
15 13
 
16 14
 @RunWith(RobolectricTestRunner.class)
17
-@Config(sdk = 25, constants = BuildConfig.class, manifest = "/../../../../../src/test/AndroidManifest.xml")
15
+@Config(sdk = 27, application = TestApplication.class)
18 16
 public abstract class BaseTest {
19 17
 	@Before
20 18
 	public void beforeEach() {
@@ -27,7 +25,7 @@ public abstract class BaseTest {
27 25
 	}
28 26
 
29 27
 	public Activity newActivity() {
30
-		return Robolectric.setupActivity(Activity.class);
28
+		return Robolectric.setupActivity(AppCompatActivity.class);
31 29
 	}
32 30
 
33 31
 	public void assertIsChildById(ViewGroup parent, View child) {

+ 5
- 0
lib/android/app/src/test/java/com/reactnativenavigation/TestApplication.java Ver fichero

@@ -3,4 +3,9 @@ package com.reactnativenavigation;
3 3
 import android.app.Application;
4 4
 
5 5
 public class TestApplication extends Application {
6
+	@Override
7
+	public void onCreate() {
8
+		super.onCreate();
9
+		setTheme(R.style.Theme_AppCompat);
10
+	}
6 11
 }

+ 5
- 9
lib/android/app/src/test/java/com/reactnativenavigation/utils/UiUtilsTest.java Ver fichero

@@ -1,21 +1,17 @@
1 1
 package com.reactnativenavigation.utils;
2 2
 
3
-import android.view.View;
3
+import android.view.*;
4 4
 
5
-import com.reactnativenavigation.BaseTest;
5
+import com.reactnativenavigation.*;
6 6
 
7
-import org.junit.Test;
8
-import org.robolectric.shadow.api.Shadow;
7
+import org.junit.*;
9 8
 
10
-import static org.mockito.Mockito.mock;
11
-import static org.mockito.Mockito.times;
12
-import static org.mockito.Mockito.verify;
13
-import static org.mockito.Mockito.verifyZeroInteractions;
9
+import static org.mockito.Mockito.*;
14 10
 
15 11
 public class UiUtilsTest extends BaseTest {
16 12
 	@Test
17 13
 	public void runOnPreDrawOnce() throws Exception {
18
-		View view = Shadow.newInstanceOf(View.class);
14
+		View view = new View(newActivity());
19 15
 		Runnable task = mock(Runnable.class);
20 16
 		verifyZeroInteractions(task);
21 17
 

+ 1
- 1
lib/android/gradle/wrapper/gradle-wrapper.properties Ver fichero

@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
3 3
 distributionPath=wrapper/dists
4 4
 zipStoreBase=GRADLE_USER_HOME
5 5
 zipStorePath=wrapper/dists
6
-distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip
6
+distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-bin.zip

+ 12
- 11
lib/android/prepare-robolectric.gradle Ver fichero

@@ -1,20 +1,18 @@
1
-def robolectricDependenciesFolder = new File(rootProject.buildDir, "robolectric-3.3-dependencies")
1
+def robolectricDependenciesFolder = new File(rootProject.buildDir, "robolectric-3.5.1-dependencies")
2 2
 
3 3
 configurations.create('robolectricRuntime')
4 4
 
5 5
 dependencies {
6 6
     testCompile "org.khronos:opengl-api:gl1.1-android-2.1_r1"
7 7
 
8
-    robolectricRuntime "org.robolectric:android-all:7.1.0_r7-robolectric-0"
9
-    robolectricRuntime "org.robolectric:shadows-core:3.3"
10
-    robolectricRuntime "org.robolectric:robolectric-utils:3.3"
11
-    robolectricRuntime "org.robolectric:robolectric-resources:3.3"
12
-    robolectricRuntime "org.robolectric:robolectric-processor:3.3"
13
-    robolectricRuntime "org.robolectric:robolectric-sandbox:3.3"
14
-    robolectricRuntime "org.robolectric:shadows-support-v4:3.3"
15
-    robolectricRuntime "org.robolectric:shadows-multidex:3.3"
16
-    robolectricRuntime "org.robolectric:shadows-play-services:3.3"
17
-    robolectricRuntime "org.robolectric:shadows-maps:3.3"
8
+    robolectricRuntime "org.robolectric:android-all:8.1.0-robolectric-4402310"
9
+
10
+    robolectricRuntime "org.robolectric:annotations:3.5.1"
11
+    robolectricRuntime "org.robolectric:junit:3.5.1"
12
+    robolectricRuntime "org.robolectric:resources:3.5.1"
13
+    robolectricRuntime "org.robolectric:sandbox:3.5.1"
14
+    robolectricRuntime "org.robolectric:utils:3.5.1"
15
+    robolectricRuntime "org.robolectric:shadows-framework:3.5.1"
18 16
 }
19 17
 
20 18
 rootProject.task(type: Copy, overwrite: true, "downloadRobolectricDependencies") {
@@ -33,6 +31,9 @@ project.afterEvaluate {
33 31
 
34 32
 android {
35 33
     testOptions {
34
+        unitTests {
35
+            includeAndroidResources = true
36
+        }
36 37
         unitTests.all {
37 38
             systemProperty 'robolectric.offline', 'true'
38 39
             systemProperty 'robolectric.dependency.dir', robolectricDependenciesFolder