refactor(test): [Login] Update test annotations to use Kotlin test framework#4529
refactor(test): [Login] Update test annotations to use Kotlin test framework#4529
Conversation
739f5d7 to
f7aee02
Compare
ea33848 to
0f78bd4
Compare
There was a problem hiding this comment.
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 severalcommonTestclasses. - Switched JUnit assertions/imports to
kotlin.testinGetInitialScreenUseCaseTest. - Removed unused Koin test dependencies from
commonTestinlogin/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@BeforeTestbut there is no correspondingDispatchers.resetMain()cleanup. This can affect subsequent tests in the same run. Add an@AfterTestto 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 underlogin/src/commonTest(e.g.,authentication/ui/viewmodel/TwoFASettingsViewModelTest.kt,main/domain/usecase/LoginUserTest.kt). WithcommonTestdepending onkotlin("test"), leaving JUnit-based annotations in common sources is inconsistent and may break non-JVM metadata compilation. Either migrate the remaining tests tokotlin.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.
login/src/commonTest/kotlin/org/dhis2/mobile/login/pin/ui/viewmodel/PinViewModelTest.kt
Show resolved
Hide resolved
6abc190 to
e89a956
Compare
There was a problem hiding this comment.
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.
… logic Signed-off-by: andresmr <andres@dhis2.org>
…tory Signed-off-by: andresmr <andres@dhis2.org>
… screen and streamline setup Signed-off-by: andresmr <andres@dhis2.org>
…annotations Signed-off-by: andresmr <andres@dhis2.org>
Signed-off-by: andresmr <andres@dhis2.org>
e89a956 to
8c44dc7
Compare
|



Description
Replace JUnit by Kotlin Test Framework