Skip to content

refactor(test): [Login] Update test annotations to use Kotlin test framework#4529

Open
andresmr wants to merge 6 commits intodevelopfrom
Replace-JUnit-by-Kotlin-test-framework
Open

refactor(test): [Login] Update test annotations to use Kotlin test framework#4529
andresmr wants to merge 6 commits intodevelopfrom
Replace-JUnit-by-Kotlin-test-framework

Conversation

@andresmr
Copy link
Collaborator

@andresmr andresmr commented Dec 1, 2025

Description

Replace JUnit by Kotlin Test Framework

@andresmr andresmr force-pushed the ANDROAPP-7220 branch 2 times, most recently from 739f5d7 to f7aee02 Compare December 10, 2025 09:57
Base automatically changed from ANDROAPP-7220 to develop December 10, 2025 15:00
@andresmr andresmr force-pushed the Replace-JUnit-by-Kotlin-test-framework branch from ea33848 to 0f78bd4 Compare February 12, 2026 10:43
Copilot AI review requested due to automatic review settings February 12, 2026 10:43
@andresmr andresmr changed the title refactor(test): update test annotations to use Kotlin test framework refactor(test): [Login] Update test annotations to use Kotlin test framework Feb 12, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the login module’s commonTest tests to use Kotlin’s kotlin.test annotations (e.g., @BeforeTest, @AfterTest) instead of JUnit annotations, aligning tests with Kotlin Multiplatform conventions.

Changes:

  • Replaced JUnit lifecycle annotations (@Before, @After) with Kotlin test equivalents (@BeforeTest, @AfterTest) across several commonTest classes.
  • Switched JUnit assertions/imports to kotlin.test in GetInitialScreenUseCaseTest.
  • Removed unused Koin test dependencies from commonTest in login/build.gradle.kts.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
login/src/commonTest/kotlin/org/dhis2/mobile/login/pin/ui/viewmodel/PinViewModelTest.kt Replace JUnit @Before with @BeforeTest for KMP-friendly test lifecycle.
login/src/commonTest/kotlin/org/dhis2/mobile/login/pin/domain/usecase/ValidatePinUseCaseTest.kt Replace JUnit @Before with @BeforeTest.
login/src/commonTest/kotlin/org/dhis2/mobile/login/pin/domain/usecase/SavePinUseCaseTest.kt Replace JUnit @Before with @BeforeTest.
login/src/commonTest/kotlin/org/dhis2/mobile/login/pin/domain/usecase/GetInitialScreenUseCaseTest.kt Replace JUnit imports/@Before and assertion import with kotlin.test equivalents.
login/src/commonTest/kotlin/org/dhis2/mobile/login/pin/domain/usecase/ForgotPinUseCaseTest.kt Replace JUnit @Before with @BeforeTest.
login/src/commonTest/kotlin/org/dhis2/mobile/login/main/ui/viewmodel/LoginViewModelTest.kt Replace JUnit @Before with @BeforeTest.
login/src/commonTest/kotlin/org/dhis2/mobile/login/main/ui/viewmodel/CredentialsViewModelTest.kt Replace JUnit @Before/@After/@Test imports with kotlin.test equivalents.
login/src/commonTest/kotlin/org/dhis2/mobile/login/main/LoginScreenIntegrationTest.kt Expand KDoc scenario description with Given/When/Then and examples table.
login/build.gradle.kts Remove Koin test dependencies from commonTest source set.
Comments suppressed due to low confidence (2)

login/src/commonTest/kotlin/org/dhis2/mobile/login/main/ui/viewmodel/LoginViewModelTest.kt:50

  • Dispatchers.setMain(testDispatcher) is configured in @BeforeTest but there is no corresponding Dispatchers.resetMain() cleanup. This can affect subsequent tests in the same run. Add an @AfterTest to reset Main after each test.
    @BeforeTest
    fun setUp() {
        Dispatchers.setMain(testDispatcher)
        whenever(appLinkNavigation.appLink).thenReturn(mockAppLinkFlow)
        whenever(networkStatusProvider.connectionStatus).thenReturn(mockNetworkStatusFlow)
    }

login/build.gradle.kts:65

  • PR description says JUnit is being replaced by Kotlin test, but there are still org.junit.* imports under login/src/commonTest (e.g., authentication/ui/viewmodel/TwoFASettingsViewModelTest.kt, main/domain/usecase/LoginUserTest.kt). With commonTest depending on kotlin("test"), leaving JUnit-based annotations in common sources is inconsistent and may break non-JVM metadata compilation. Either migrate the remaining tests to kotlin.test.* or move them to a JVM-only source set (or keep the required JUnit deps explicitly).
        commonTest {
            dependencies {
                implementation(kotlin("test"))
                implementation(libs.test.turbine)
                implementation(libs.test.kotlinCoroutines)
                implementation(libs.test.mockitoKotlin)
                implementation(compose.components.resources)
            }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings February 13, 2026 06:14
@andresmr andresmr force-pushed the Replace-JUnit-by-Kotlin-test-framework branch from 6abc190 to e89a956 Compare February 13, 2026 06:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

login/src/commonTest/kotlin/org/dhis2/mobile/login/main/ui/viewmodel/LoginViewModelTest.kt:50

  • The test class sets the main dispatcher in the setUp method but lacks a corresponding tearDown method with @AfterTest annotation to reset the dispatcher. This can cause test isolation issues and resource leaks. Other test files in this PR (PinViewModelTest.kt and CredentialsViewModelTest.kt) properly include @AfterTest methods that call Dispatchers.resetMain(). Add a tearDown method with @AfterTest annotation that calls Dispatchers.resetMain(), and import kotlinx.coroutines.test.resetMain.
    @BeforeTest
    fun setUp() {
        Dispatchers.setMain(testDispatcher)
        whenever(appLinkNavigation.appLink).thenReturn(mockAppLinkFlow)
        whenever(networkStatusProvider.connectionStatus).thenReturn(mockNetworkStatusFlow)
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@andresmr andresmr force-pushed the Replace-JUnit-by-Kotlin-test-framework branch from e89a956 to 8c44dc7 Compare February 13, 2026 10:00
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants