Skip to content

Fix tests#118

Merged
KCeh merged 4 commits into
masterfrom
fix/tests
Jan 6, 2026
Merged

Fix tests#118
KCeh merged 4 commits into
masterfrom
fix/tests

Conversation

@KCeh

@KCeh KCeh commented Jan 4, 2026

Copy link
Copy Markdown
Collaborator

📄 Context

I used agentic AI to help fix all unit tests.

📝 Changes

Test Library Updates:
Coroutines: 1.6.4 → 1.7.3
Turbine: 0.12.0 → 1.0.0

Pattern for fix

// BEFORE:
@Test
fun `Some test`() {
    test {
        viewModel.someAction()
        coVerify { ... }
        viewModel.stateFlow.test {
            awaitItem()
            awaitCancellation()
        }
    }
}

// AFTER:
@Test
fun `Some test`() = test {
    viewModel.someAction()
    advanceUntilIdle()
    
    coVerify { ... }
    
    val state = viewModel.stateFlow.filterNotNull().first()
    // assertions
    
    assertNull(viewModel.errorFlow.value)
}

📎 Related PR

🚫 Breaking

🛠️ How to test

⏱️ Next steps

I will read CoPilot's review and fix things if needed

@KCeh KCeh requested a review from Copilot January 4, 2026 15:48
@KCeh KCeh self-assigned this Jan 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown

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 test library dependencies and refactors test code to align with Turbine 1.0.0 and Coroutines 1.7.3 APIs. The changes migrate from nested test {} blocks to a cleaner = test syntax and replace deprecated Turbine methods with their modern equivalents.

  • Updated Coroutines from 1.6.4 to 1.7.3 and Turbine from 0.12.0 to 1.0.0
  • Refactored all test functions to use = test syntax instead of nested test {} blocks
  • Replaced awaitCancellation() with cancelAndIgnoreRemainingEvents() and added advanceUntilIdle() calls after async operations

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
gradle/libs.versions.toml Updated test library versions for coroutines and turbine
LifecycleViewModelTest.kt Refactored test syntax to use = test pattern and added advanceUntilIdle() calls
SettingsViewModelTest.kt Migrated to new test patterns with flow testing using Turbine 1.0.0 APIs
SchemaSourceViewModelTest.kt Updated test structure with new flow assertions and removed nested test blocks
PragmaSourceViewModelTest.kt Refactored to match new test patterns with Turbine 1.0.0
HistoryViewModelTest.kt Updated test flows and replaced deprecated Turbine methods
EditViewModelTest.kt Migrated to new test syntax with updated flow handling
RenameDatabaseViewModelTest.kt Refactored with new flow assertion patterns
RemoveDatabaseViewModelTest.kt Updated to use new test structure
DatabaseViewModelTest.kt Added dispatcher management and refactored test flows
ContentViewModelTest.kt Migrated to new test patterns with updated Turbine APIs

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

@KCeh KCeh requested a review from Copilot January 4, 2026 16:01
@sonarqubecloud

sonarqubecloud Bot commented Jan 4, 2026

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown

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 15 out of 15 changed files in this pull request and generated 8 comments.

Comments suppressed due to low confidence (2)

dbinspector/src/test/kotlin/com/infinum/dbinspector/ui/edit/EditViewModelTest.kt:296

  • This test that is marked as @disabled was not refactored to the new test pattern. It still uses the old nested test blocks. Since the test is disabled, it should either be updated to the new pattern for consistency or removed if it's no longer needed.
    @Test
    @Disabled("Unfinished coroutines during teardown.")
    fun `Get all history`() {
        val useCase: UseCases.GetHistory = get()
        val viewModel = EditViewModel(
            get(),
            get(),
            get(),
            get(),
            get(),
            get(),
            get(),
            useCase,
            get(),
            get()
        ).apply {
            databasePath = "test.db"
        }

        coEvery { useCase.invoke(any()) } returns mockk()

        test {
            viewModel.history()
        }

        coVerify(exactly = 1) { useCase.invoke(any()) }
        test {
            viewModel.stateFlow.test {
                assertNull(awaitItem())
            }
            viewModel.eventFlow.test {
                val item: EditEvent? = awaitItem()
                assertTrue(item is EditEvent.History)
                assertNotNull(item.history)
                cancelAndIgnoreRemainingEvents()
            }
            viewModel.errorFlow.test {
                expectNoEvents()
            }
        }
    }

dbinspector/src/test/kotlin/com/infinum/dbinspector/ui/edit/EditViewModelTest.kt:337

  • This test that is marked as @disabled was not refactored to the new test pattern. It still uses the old nested test blocks. Since the test is disabled, it should either be updated to the new pattern for consistency or removed if it's no longer needed.
    @Test
    @Disabled("How to test with delay")
    fun `Find similar execution`() {
        test {
            val useCase: UseCases.GetSimilarExecution = get()
            val viewModel = EditViewModel(
                get(),
                get(),
                get(),
                get(),
                get(),
                get(),
                get(),
                get(),
                useCase,
                get()
            ).apply {
                databasePath = "test.db"
            }

            coEvery { useCase.invoke(any()) } returns mockk()

            viewModel.findSimilarExecution(TestScope(), "my_execution")

            coVerify(exactly = 1) { useCase.invoke(any()) }

            viewModel.stateFlow.test {
                assertNull(awaitItem())
            }
            viewModel.eventFlow.test {
                val item: EditEvent? = awaitItem()
                assertTrue(item is EditEvent.SimilarExecution)
                assertNotNull(item.history)
                cancelAndIgnoreRemainingEvents()
            }
            viewModel.errorFlow.test {
                expectNoEvents()
            }
        }
    }

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

@KCeh

KCeh commented Jan 4, 2026

Copy link
Copy Markdown
Collaborator Author

There seem to be flaky tests 😅
We can improve this at a later point.

@KCeh KCeh mentioned this pull request Jan 4, 2026
@KCeh KCeh merged commit e9e5821 into master Jan 6, 2026
28 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants