diff --git a/.gitea/workflows/on_push_testing.yml b/.gitea/workflows/on_push_coverage.yml similarity index 78% rename from .gitea/workflows/on_push_testing.yml rename to .gitea/workflows/on_push_coverage.yml index 8670c15..7ddce84 100644 --- a/.gitea/workflows/on_push_testing.yml +++ b/.gitea/workflows/on_push_coverage.yml @@ -5,7 +5,7 @@ on: - testing jobs: - checkout: + coverage: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -28,14 +28,13 @@ jobs: - uses: android-actions/setup-android@v3 - name: Configure gradle... run: mkdir -p ~/.gradle && echo "org.gradle.daemon=false\nignoreGitVersion=true" >> ~/.gradle/gradle.properties - - name: Robolectric tests + - name: coverage run: | - ./gradlew :androidApp:testGithubConfigDebugUnitTest --tests "bou.amine.apps.readerforselfossv2.android.tests.robolectric.*" + ./gradlew :koverHtmlReport - uses: actions/upload-artifact@v3 - if: failure() with: - name: robot-tests - path: androidApp/build/test-results/testGithubConfigDebugUnitTest + name: coverage + path: build/reports/kover/html retention-days: 1 overwrite: true include-hidden-files: true diff --git a/androidApp/build.gradle.kts b/androidApp/build.gradle.kts index 4df25df..dc12389 100644 --- a/androidApp/build.gradle.kts +++ b/androidApp/build.gradle.kts @@ -113,9 +113,6 @@ android { execution = "ANDROIDX_TEST_ORCHESTRATOR" unitTests { isIncludeAndroidResources = true - all { - it.systemProperty("robolectric.logging.enabled", true) - } } } @@ -202,10 +199,11 @@ dependencies { androidTestImplementation("androidx.test.ext:junit-ktx:1.2.1") androidTestUtil("androidx.test:orchestrator:1.5.1") testImplementation("org.robolectric:robolectric:4.14.1") - + testImplementation("androidx.test:core-ktx:1.6.1") implementation("ch.acra:acra-http:$acraVersion") implementation("ch.acra:acra-toast:$acraVersion") + } tasks.withType { diff --git a/androidApp/src/test/kotlin/bou/amine/apps/readerforselfossv2/android/tests/robolectric/HomeActivityTest.kt b/androidApp/src/test/kotlin/bou/amine/apps/readerforselfossv2/android/tests/robolectric/HomeActivityTest.kt deleted file mode 100644 index c2ce319..0000000 --- a/androidApp/src/test/kotlin/bou/amine/apps/readerforselfossv2/android/tests/robolectric/HomeActivityTest.kt +++ /dev/null @@ -1,94 +0,0 @@ -package bou.amine.apps.readerforselfossv2.android.tests.robolectric - -import android.view.View -import bou.amine.apps.readerforselfossv2.android.HomeActivity -import bou.amine.apps.readerforselfossv2.android.R -import bou.amine.apps.readerforselfossv2.service.ACRASettings -import bou.amine.apps.readerforselfossv2.service.AppSettingsService.Companion.BASE_URL -import bou.amine.apps.readerforselfossv2.service.AppSettingsService.Companion.LOGIN -import bou.amine.apps.readerforselfossv2.service.AppSettingsService.Companion.PASSWORD -import io.mockk.every -import io.mockk.mockk -import org.junit.Assert.assertEquals -import org.junit.Assert.assertNotNull -import org.junit.Assert.assertTrue -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.robolectric.Robolectric -import org.robolectric.Shadows - -@RunWith(RobotElectriqueRunnerclass::class) -class HomeActivityTest { - - - @Before - fun setUp() { - val settings = mockk() - every { settings.getString(PASSWORD, "") } returns "" - every { settings.getString(LOGIN, "") } returns "" - every { settings.getString(BASE_URL, "") } returns "http://10.0.2.2:8888" - } - - @Test - fun testMenu() { - Robolectric.buildActivity(HomeActivity::class.java).use { controller -> - controller.setup() // Moves the Activity to the RESUMED state - - val activity = controller.get() - val searchMenuItem = activity.findViewById(R.id.action_search) - try { - assertNotNull(searchMenuItem) - assertTrue(searchMenuItem.visibility == View.VISIBLE) - assertTrue(searchMenuItem.isClickable) - - val filterMenuItem = activity.findViewById(R.id.action_filter) - assertNotNull(filterMenuItem) - assertTrue(filterMenuItem.visibility == View.VISIBLE) - assertTrue(filterMenuItem.isClickable) - - // Simulate opening the options menu - Shadows.shadowOf(activity) - .clickMenuItem(R.id.action_search) // or R.id.action_filter, ... - - // Assert menu items are displayed - // You'll need to find the menu items using Robolectric APIs - // and assert their visibility, for example: - // val readAllMenuItem = Shadows.shadowOf(activity).optionsMenu.findItem(R.id.readAll) - // assertNotNull(readAllMenuItem) - // assertTrue(readAllMenuItem.isVisible) - } catch (e: Throwable) { - val screenshot = Screenshot.takeScreenshot(activity) - screenshot.save(File("screenshots"), "myTestFailure") - throw e - } - } - } - - @Test - fun testMenuActions() { - // Simulate menu item clicks and assert the expected behavior - // using Robolectric APIs, for example: - // Shadows.shadowOf(activity).clickMenuItem(R.id.action_search) - // val searchEditText = activity.findViewById(R.id.search_src_text) - // assertTrue(searchEditText.hasFocus()) - } - - @Test - fun testEmptyView() { - Robolectric.buildActivity(HomeActivity::class.java).use { controller -> - controller.setup() // Moves the Activity to the RESUMED state - - val activity = controller.get() - val emptyView = activity.findViewById(R.id.emptyText) - assertNotNull(emptyView) - assertEquals(View.VISIBLE, emptyView.visibility) - - // Assert bottom bar items - // You'll need to find the bottom bar items using Robolectric APIs - // and assert their visibility and selection state, for example: - // val newTabItem = activity.findViewById(R.id.tab_new) - // assertTrue(newTabItem.isSelected) - } - } -} \ No newline at end of file diff --git a/androidApp/src/test/kotlin/bou/amine/apps/readerforselfossv2/android/tests/robolectric/LoginActivityTest.kt b/androidApp/src/test/kotlin/bou/amine/apps/readerforselfossv2/android/tests/robolectric/LoginActivityTest.kt index 9dd85e0..2dd513c 100644 --- a/androidApp/src/test/kotlin/bou/amine/apps/readerforselfossv2/android/tests/robolectric/LoginActivityTest.kt +++ b/androidApp/src/test/kotlin/bou/amine/apps/readerforselfossv2/android/tests/robolectric/LoginActivityTest.kt @@ -1,10 +1,8 @@ package bou.amine.apps.readerforselfossv2.android.tests.robolectric -import android.content.Intent import android.widget.Button import android.widget.EditText import androidx.core.view.isVisible -import bou.amine.apps.readerforselfossv2.android.HomeActivity import bou.amine.apps.readerforselfossv2.android.LoginActivity import bou.amine.apps.readerforselfossv2.android.R import com.google.android.material.switchmaterial.SwitchMaterial @@ -12,8 +10,6 @@ import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith import org.robolectric.Robolectric -import org.robolectric.RuntimeEnvironment -import org.robolectric.Shadows.shadowOf @RunWith(RobotElectriqueRunnerclass::class) @@ -63,19 +59,19 @@ class LoginActivityTest { } } - @Test - fun connect() { - Robolectric.buildActivity(LoginActivity::class.java).use { controller -> - controller.setup() // Moves the Activity to the RESUMED state - val activity = controller.get() - val signInButton = activity.findViewById