Skip to content

Commit 067c24b

Browse files
Instrumented tests ci (#386)
* Trial and error - add instrumented tests to CI * Trial and error - add instrumented tests to CI Setup AVD * Trial and error - add instrumented tests to CI Fix action version * Try API level 27 for AVD ReactiveCircus/android-emulator-runner#45 * Try API level 29 for AVD on macos-latest image ReactiveCircus/android-emulator-runner#45 * Explicitly watch instrumented test fail * Fix instrumented tests and prepare merge into master
1 parent 7126813 commit 067c24b

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

.github/workflows/android.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- uses: gradle/wrapper-validation-action@v1
1111

1212
test:
13-
name: Run Unit Tests
13+
name: Unit tests
1414
runs-on: ubuntu-18.04
1515

1616
steps:
@@ -22,6 +22,22 @@ jobs:
2222
- name: Unit tests
2323
run: bash ./gradlew test --stacktrace
2424

25+
instrumented:
26+
name: Android instrumented tests
27+
runs-on: macos-latest
28+
29+
steps:
30+
- uses: actions/checkout@v2
31+
- name: set up JDK 1.8
32+
uses: actions/setup-java@v1
33+
with:
34+
java-version: 1.8
35+
- name: Android instrumented tests
36+
uses: reactivecircus/android-emulator-runner@v2
37+
with:
38+
api-level: 29
39+
script: ./gradlew connectDevDebugAndroidTest --stacktrace
40+
2541
apk:
2642
name: Generate APK
2743
runs-on: ubuntu-18.04

app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ android {
1616
}
1717
}
1818
multiDexEnabled true
19+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1920
}
2021
buildTypes {
2122
release {
@@ -123,5 +124,6 @@ dependencies {
123124
// Tests
124125
testImplementation 'junit:junit:4.13'
125126
androidTestImplementation 'androidx.test:runner:1.2.0'
127+
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
126128
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
127129
}

app/src/androidTest/java/it/niedermann/nextcloud/deck/ExampleInstrumentedTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package it.niedermann.nextcloud.deck;
22

33
import android.content.Context;
4-
import androidx.test.InstrumentationRegistry;
5-
import androidx.test.runner.AndroidJUnit4;
4+
5+
import androidx.test.ext.junit.runners.AndroidJUnit4;
6+
import androidx.test.platform.app.InstrumentationRegistry;
67

78
import org.junit.Test;
89
import org.junit.runner.RunWith;
@@ -19,8 +20,8 @@ public class ExampleInstrumentedTest {
1920
@Test
2021
public void useAppContext() {
2122
// Context of the app under test.
22-
Context appContext = InstrumentationRegistry.getTargetContext();
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
2324

24-
assertEquals("it.niedermann.nextcloud.deck", appContext.getPackageName());
25+
assertEquals("it.niedermann.nextcloud.deck.dev", appContext.getPackageName());
2526
}
2627
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package it.niedermann.nextcloud.deck.util;
2+
3+
import android.graphics.Color;
4+
5+
import androidx.annotation.ColorInt;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.assertFalse;
12+
import static org.junit.Assert.assertTrue;
13+
14+
/**
15+
* Instrumented test, which will execute on an Android device.
16+
*
17+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
18+
*/
19+
@RunWith(AndroidJUnit4.class)
20+
public class ColorUtilTest {
21+
22+
@Test
23+
public void testIsColorDark() {
24+
@ColorInt int[] darkColors = new int[]{Color.BLACK};
25+
@ColorInt int[] lightColors = new int[]{Color.WHITE};
26+
for (@ColorInt int darkColor : darkColors) {
27+
assertTrue(ColorUtil.isColorDark(darkColor));
28+
}
29+
for (@ColorInt int lightColor : lightColors) {
30+
assertFalse(ColorUtil.isColorDark(lightColor));
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)