Repository navigation
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.slnxThe 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.
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 everyTask/ValueTask-returning method ends inAsync. A new project needs aProjectReferencefromKHost.UnitTeststo 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.
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. -
EnvironmentCoverageTestsis 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. SetKHOST_SKIP_ENVIRONMENT_TESTS=1to accept the gap. -
Cast tests (
CastServiceTests) drive a real CASTV2 receiver and need the Chromecast-Emulator listening on127.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).
KHost
Architecture
- Architecture
- Projects
- Screens and Casting
- Break Music and Ads
- Messaging
- Data and Persistence
- Plugins
Contributing