From da10499b7d1e679ab6aedc5b7eae217e018c53f0 Mon Sep 17 00:00:00 2001 From: Unpublished Date: Tue, 9 Apr 2019 20:56:54 +0200 Subject: [PATCH] update to robolectric 4.2.1, fix unit test and include test in ci --- .circleci/config.yml | 32 ++++++++++++++++++- News-Android-App/build.gradle | 4 ++- .../junit_tests/TestDbTest.java | 22 ++----------- gradle.properties | 3 +- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5d1e4e22..bcad8b3d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,9 +26,39 @@ jobs: - store_artifacts: path: News-Android-App/build/outputs/apk destination: apks + - persist_to_workspace: + root: News-Android-App + paths: + - build + + test: + docker: + - image: circleci/android:api-28 + environment: + JVM_OPTS: -Xmx3200m + steps: + - checkout + - attach_workspace: + at: News-Android-App + - restore_cache: + key: jars-{{ checksum "build.gradle" }}-{{ checksum "News-Android-App/build.gradle" }} + - run: + name: chmod permissions + command: chmod +x ./gradlew + - run: + name: Run unit tests + command: ./gradlew test + - store_artifacts: + path: News-Android-App/build/reports + destination: reports + - store_test_results: + path: News-Android-App/build/test-results workflows: version: 2 - build: + build-test: jobs: - build + - test: + requires: + - build diff --git a/News-Android-App/build.gradle b/News-Android-App/build.gradle index 90b43e92..eaa270af 100644 --- a/News-Android-App/build.gradle +++ b/News-Android-App/build.gradle @@ -12,6 +12,8 @@ android { compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION) buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION + testOptions.unitTests.includeAndroidResources = true + defaultConfig { minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION) targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION) @@ -198,7 +200,7 @@ dependencies { //androidTestImplementation 'com.google.dexmaker:dexmaker:1.2' //androidTestImplementation 'com.google.dexmaker:dexmaker-mockito:1.2' - //androidTestImplementation 'org.robolectric:robolectric:3.0-rc3' + testImplementation 'org.robolectric:robolectric:4.2.1' // Core library androidTestImplementation 'androidx.test:core:1.1.0' diff --git a/News-Android-App/src/test/java/de/luhmer/owncloudnewsreader/junit_tests/TestDbTest.java b/News-Android-App/src/test/java/de/luhmer/owncloudnewsreader/junit_tests/TestDbTest.java index 4a8b43fe..3d0cd7b1 100644 --- a/News-Android-App/src/test/java/de/luhmer/owncloudnewsreader/junit_tests/TestDbTest.java +++ b/News-Android-App/src/test/java/de/luhmer/owncloudnewsreader/junit_tests/TestDbTest.java @@ -4,23 +4,18 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; -import org.robolectric.RobolectricGradleTestRunner; -import org.robolectric.annotation.Config; +import org.robolectric.RobolectricTestRunner; import java.security.SecureRandom; import java.util.ArrayList; import java.util.List; -import de.luhmer.owncloudnewsreader.BuildConfig; import de.luhmer.owncloudnewsreader.NewsReaderListActivity; import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm; import de.luhmer.owncloudnewsreader.database.model.Feed; import de.luhmer.owncloudnewsreader.database.model.RssItem; -import static org.junit.Assert.assertTrue; - -@RunWith(RobolectricGradleTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 21) +@RunWith(RobolectricTestRunner.class) public class TestDbTest { private NewsReaderListActivity activity; @@ -32,19 +27,6 @@ public class TestDbTest { activity = Robolectric.buildActivity(NewsReaderListActivity.class).create().get(); } - @Test - public void test() { - assertTrue(true); - } - - /* - @Test - public void checkActivityNotNull() throws Exception { - assertNotNull(activity); - } - */ - - @Test public void testDatabaseOversize() { final DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(activity); diff --git a/gradle.properties b/gradle.properties index fb4ce4b5..364555be 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,4 +22,5 @@ ANDROID_BUILD_TARGET_SDK_VERSION=28 ANDROID_BUILD_TOOLS_VERSION=28.0.3 ANDROID_BUILD_SDK_VERSION=28 android.useAndroidX=true -android.enableJetifier=true \ No newline at end of file +android.enableJetifier=true +android.enableUnitTestBinaryResources=true