Quellcode durchsuchen

revert remove robolectric - prepare for android navigation stack

Daniel Zlotin vor 7 Jahren
Ursprung
Commit
5c960ffa4a

+ 2
- 1
lib/android/app/build.gradle Datei anzeigen

@@ -1,4 +1,5 @@
1 1
 apply plugin: 'com.android.library'
2
+apply from: '../prepare-robolectric.gradle'
2 3
 
3 4
 android {
4 5
     compileSdkVersion 25
@@ -56,7 +57,7 @@ dependencies {
56 57
 
57 58
     // tests
58 59
     testCompile 'junit:junit:4.12'
60
+    testCompile 'org.robolectric:robolectric:3.3'
59 61
     testCompile 'org.assertj:assertj-core:2.5.0'
60 62
     testCompile 'org.mockito:mockito-core:2.7.5'
61
-    testCompile 'org.json:json:20140107'
62 63
 }

+ 8
- 0
lib/android/app/src/test/AndroidManifest.xml Datei anzeigen

@@ -0,0 +1,8 @@
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>

+ 6
- 0
lib/android/app/src/test/java/com/reactnativenavigation/BaseTest.java Datei anzeigen

@@ -1,5 +1,11 @@
1 1
 package com.reactnativenavigation;
2 2
 
3
+import org.junit.runner.RunWith;
4
+import org.robolectric.RobolectricTestRunner;
5
+import org.robolectric.annotation.Config;
6
+
7
+@RunWith(RobolectricTestRunner.class)
8
+@Config(sdk = 25, constants = BuildConfig.class, manifest = "/../../../../../src/test/AndroidManifest.xml")
3 9
 public abstract class BaseTest {
4 10
 
5 11
 }

+ 6
- 0
lib/android/app/src/test/java/com/reactnativenavigation/EnvironmentTest.java Datei anzeigen

@@ -6,6 +6,7 @@ import android.support.v7.app.AppCompatActivity;
6 6
 import com.facebook.react.common.ReactConstants;
7 7
 
8 8
 import org.junit.Test;
9
+import org.robolectric.RuntimeEnvironment;
9 10
 
10 11
 import static org.assertj.core.api.Java6Assertions.assertThat;
11 12
 
@@ -34,4 +35,9 @@ public class EnvironmentTest extends BaseTest {
34 35
 	public void androidR() {
35 36
 		assertThat(R.string.bottom_sheet_behavior).isNotZero();
36 37
 	}
38
+
39
+	@Test
40
+	public void ableToLoadApplication() throws Exception {
41
+		assertThat(RuntimeEnvironment.application).isNotNull();
42
+	}
37 43
 }

+ 6
- 0
lib/android/app/src/test/java/com/reactnativenavigation/TestApplication.java Datei anzeigen

@@ -0,0 +1,6 @@
1
+package com.reactnativenavigation;
2
+
3
+import android.app.Application;
4
+
5
+public class TestApplication extends Application {
6
+}

+ 32
- 0
lib/android/app/src/test/java/com/reactnativenavigation/utils/UiThreadTest.java Datei anzeigen

@@ -0,0 +1,32 @@
1
+package com.reactnativenavigation.utils;
2
+
3
+import com.reactnativenavigation.BaseTest;
4
+
5
+import org.junit.Test;
6
+import org.robolectric.shadows.ShadowLooper;
7
+
8
+import static org.mockito.Mockito.mock;
9
+import static org.mockito.Mockito.times;
10
+import static org.mockito.Mockito.verify;
11
+import static org.mockito.Mockito.verifyZeroInteractions;
12
+
13
+public class UiThreadTest extends BaseTest {
14
+	@Test
15
+	public void postOnUiThread() throws Exception {
16
+		Runnable task = mock(Runnable.class);
17
+		ShadowLooper.pauseMainLooper();
18
+		UiThread.post(task);
19
+		verifyZeroInteractions(task);
20
+		ShadowLooper.runUiThreadTasks();
21
+		verify(task, times(1)).run();
22
+	}
23
+
24
+	@Test
25
+	public void postDelayedOnUiThread() throws Exception {
26
+		Runnable task = mock(Runnable.class);
27
+		UiThread.postDelayed(task, 1000);
28
+		verifyZeroInteractions(task);
29
+		ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
30
+		verify(task, times(1)).run();
31
+	}
32
+}

+ 26
- 0
lib/android/app/src/test/java/com/reactnativenavigation/utils/UiUtilsTest.java Datei anzeigen

@@ -0,0 +1,26 @@
1
+package com.reactnativenavigation.utils;
2
+
3
+import android.view.View;
4
+
5
+import com.reactnativenavigation.BaseTest;
6
+
7
+import org.junit.Test;
8
+import org.robolectric.shadow.api.Shadow;
9
+
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;
14
+
15
+public class UiUtilsTest extends BaseTest {
16
+	@Test
17
+	public void runOnPreDrawOnce() throws Exception {
18
+		View view = Shadow.newInstanceOf(View.class);
19
+		Runnable task = mock(Runnable.class);
20
+		verifyZeroInteractions(task);
21
+
22
+		UiUtils.runOnPreDrawOnce(view, task);
23
+		view.getViewTreeObserver().dispatchOnPreDraw();
24
+		verify(task, times(1)).run();
25
+	}
26
+}

+ 42
- 0
lib/android/prepare-robolectric.gradle Datei anzeigen

@@ -0,0 +1,42 @@
1
+def robolectricDependenciesFolder = new File(rootProject.buildDir, "robolectric-3.3-dependencies")
2
+
3
+configurations.create('robolectricRuntime')
4
+
5
+dependencies {
6
+    testCompile "org.khronos:opengl-api:gl1.1-android-2.1_r1"
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"
18
+}
19
+
20
+rootProject.task(type: Copy, overwrite: true, "downloadRobolectricDependencies") {
21
+    println "downloadRobolectricDependencies into " + robolectricDependenciesFolder
22
+    from configurations.robolectricRuntime
23
+    into robolectricDependenciesFolder
24
+}
25
+
26
+project.afterEvaluate {
27
+    tasks.all {
28
+        if (it.name.startsWith("test")) {
29
+            it.dependsOn(rootProject.tasks.findByName("downloadRobolectricDependencies"))
30
+        }
31
+    }
32
+}
33
+
34
+android {
35
+    testOptions {
36
+        unitTests.all {
37
+            systemProperty 'robolectric.offline', 'true'
38
+            systemProperty 'robolectric.dependency.dir', robolectricDependenciesFolder
39
+        }
40
+    }
41
+}
42
+