Skip to content

Testing

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

Testing

# Just the unit tests
dotnet test tests/KHost.UnitTests

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

# Everything in the solution
dotnet test KHost.slnx

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; StateChanged is tested with a counter lambda.

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 all eight referenced assemblies asserting every Task/ValueTask-returning method ends in Async. A new project needs a ProjectReference from KHost.UnitTests to be covered.
  • EnvironmentCoverageTests — the transcode tests run real ffmpeg (and use ffprobe to assert a segment carries audio). If either is missing, this suite 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 need the Chromecast-Emulator listening on 127.0.0.1:8009; they skip (via a 1-second connect probe) when it isn't.
  • 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

Empty skeleton — only the .csproj exists (no tests, no project references). It builds and runs (0 tests) as part of the solution; new integration tests belong here.

Clone this wiki locally