Skip to content

feat(runtime-test): add runTestWithMain and JUnit4 MainCoroutinesTestRule - #173

Merged
santimattius merged 2 commits into
mainfrom
feat/runtime-test-main-167
Nov 9, 2026
Merged

santimattius merged 2 commits into
mainfrom
feat/runtime-test-main-167

Conversation

@santimattius

Copy link
Copy Markdown
Owner

Closes #167

What

  • runTestWithMain (:runtime-test, commonMain): like runTest, but installs a test dispatcher as Dispatchers.Main and always resets it, including when the block throws.
  • MainCoroutinesTestRule (new :runtime-test-junit4, JVM-only): JUnit4 TestWatcher with the same semantics, for projects that prefer @get:Rule.

Decisions

  • Default dispatcher: StandardTestDispatcher on the TestScope scheduler, so Main and testDispatcherProvider() share one virtual clock. UnconfinedTestDispatcher can hide ordering bugs; pass it explicitly if wanted.
  • Artifact placement: the rule ships as a separate artifact so :runtime-test keeps its "no transitive test libraries" guarantee.
  • runTestWithMain takes dispatcher: TestDispatcher? = null (instead of a default instance) so the default can be built on the scope's scheduler. It returns TestResult because runTest returns a promise on JS.

Verification

  • :runtime-test:jvmTest, :runtime-test-junit4:test, both apiCheck tasks: pass locally.
  • :runtime-test:compileKotlinJs, :runtime-test:compileKotlinIosSimulatorArm64: pass locally.
  • CI and publish-runtime.yml now include the new module.

The new module is wired into publishing but no release is cut here.

@santimattius
santimattius merged commit 3434c31 into main Nov 9, 2026
2 of 3 checks passed
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.

feat(runtime-test): add runTestWithMain (multiplatform) and optional JUnit4 MainCoroutinesTestRule

1 participant