Skip to content

Testing

Michael Riddle edited this page Aug 24, 2026 · 3 revisions

Testing

# The unit tests — hermetic, no skips: green means everything ran
dotnet test tests/KHost.UnitTests

# The integration tests — drive real external tools (see below)
dotnet test tests/KHost.IntegrationTests

# Narrow to one class/test
dotnet test tests/KHost.UnitTests --filter "FullyQualifiedName~Name"

# Everything in the solution
dotnet test KHost.slnx

The line between the two projects: a test that needs anything outside the process — an external binary, a live service — is an integration test. In-process I/O (temp files, in-memory SQLite) stays in the unit suite.

KHost.UnitTests

xUnit + NSubstitute. Test classes mirror the src/ layout (Domain/Services/Foo.cs → Domain/Services/FooTests.cs); names follow MethodUnderTest_Scenario_ExpectedBehavior; substitutes live in field initializers; an announcement is tested by subscribing a counter to the real broker the service was built with, or by substituting IMessageBroker and asserting Received(1).Announce(...). The suite is deliberately skip-free.

Notable infrastructure:

  • SqliteTestDatabase — repository tests run against a real in-memory SQLite database (schema from the EF model, not migrations, so the raw FTS5 SQL isn't needed). Repository LINQ only becomes real SQL at the provider, so faking the provider would test expression trees, not behavior.
  • AsyncNamingConventionTests (Conventions/) — reflection sweep across the referenced assemblies asserting every Task/ValueTask-returning method ends in Async. A new project needs a ProjectReference from KHost.UnitTests to be covered.
  • Plugin loader tests cover discovery failure modes (missing/invalid manifest, duplicate id, API version mismatch, missing entry assembly) and end-to-end load/registration.

KHost.IntegrationTests

Tests that drive real external tools, each guarding its own presence:

  • Transcode tests (HlsMediaStreamServiceTranscodeTests) run real ffmpeg and use ffprobe to assert a segment carries audio; they skip when ffmpeg is not installed.
  • EnvironmentCoverageTests is the counterweight to that skipping: if ffmpeg or ffprobe is missing, it fails the run in plain words rather than letting silently-skipped coverage read as a pass. Set KHOST_SKIP_ENVIRONMENT_TESTS=1 to accept the gap.
  • Cast tests (CastServiceTests) drive a real CASTV2 receiver and need the Chromecast-Emulator listening on 127.0.0.1:8009; they skip (via a 1-second connect probe) when it isn't. The no-receiver cast paths are covered emulator-free in the unit suite (CastServiceDisconnectedTests).

Clone this wiki locally