diff options
4 files changed, 57 insertions, 5 deletions
diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index ccf380909..5700a0dce 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -10,7 +10,7 @@ jobs: - uses: gradle/wrapper-validation-action@v1 test: - name: Run Unit Tests + name: Unit tests runs-on: ubuntu-18.04 steps: @@ -22,6 +22,22 @@ jobs: - name: Unit tests run: bash ./gradlew test --stacktrace + instrumented: + name: Android instrumented tests + runs-on: macos-latest + + steps: + - uses: actions/checkout@v2 + - name: set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Android instrumented tests + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: 29 + script: ./gradlew connectDevDebugAndroidTest --stacktrace + apk: name: Generate APK runs-on: ubuntu-18.04 diff --git a/app/build.gradle b/app/build.gradle index 0e8536f5b..e6b6b4ceb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,6 +16,7 @@ android { } } multiDexEnabled true + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { @@ -123,5 +124,6 @@ dependencies { // Tests testImplementation 'junit:junit:4.13' androidTestImplementation 'androidx.test:runner:1.2.0' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' } diff --git a/app/src/androidTest/java/it/niedermann/nextcloud/deck/ExampleInstrumentedTest.java b/app/src/androidTest/java/it/niedermann/nextcloud/deck/ExampleInstrumentedTest.java index da95d9b20..91b3d3617 100644 --- a/app/src/androidTest/java/it/niedermann/nextcloud/deck/ExampleInstrumentedTest.java +++ b/app/src/androidTest/java/it/niedermann/nextcloud/deck/ExampleInstrumentedTest.java @@ -1,8 +1,9 @@ package it.niedermann.nextcloud.deck; import android.content.Context; -import androidx.test.InstrumentationRegistry; -import androidx.test.runner.AndroidJUnit4; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.platform.app.InstrumentationRegistry; import org.junit.Test; import org.junit.runner.RunWith; @@ -19,8 +20,8 @@ public class ExampleInstrumentedTest { @Test public void useAppContext() { // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - assertEquals("it.niedermann.nextcloud.deck", appContext.getPackageName()); + assertEquals("it.niedermann.nextcloud.deck.dev", appContext.getPackageName()); } } diff --git a/app/src/androidTest/java/it/niedermann/nextcloud/deck/util/ColorUtilTest.java b/app/src/androidTest/java/it/niedermann/nextcloud/deck/util/ColorUtilTest.java new file mode 100644 index 000000000..eaf45c813 --- /dev/null +++ b/app/src/androidTest/java/it/niedermann/nextcloud/deck/util/ColorUtilTest.java @@ -0,0 +1,33 @@ +package it.niedermann.nextcloud.deck.util; + +import android.graphics.Color; + +import androidx.annotation.ColorInt; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> + */ +@RunWith(AndroidJUnit4.class) +public class ColorUtilTest { + + @Test + public void testIsColorDark() { + @ColorInt int[] darkColors = new int[]{Color.BLACK}; + @ColorInt int[] lightColors = new int[]{Color.WHITE}; + for (@ColorInt int darkColor : darkColors) { + assertTrue(ColorUtil.isColorDark(darkColor)); + } + for (@ColorInt int lightColor : lightColors) { + assertFalse(ColorUtil.isColorDark(lightColor)); + } + } +} |