Plugin Authoring TestKit reference
Reeve.PluginAuthoring.TestKit is the NuGet package that plugin authors reference from their test project. Its source
is in github.com/reeve-iot/reeve-testkit, and the package is published
to nuget.org beside the SDK packages. The scaffolded tests/ project already references it. It provides an in-memory IPluginHostServices and a PluginHarness that
loads your DLL into its own load context and creates the plugin through its factory, so unit tests assert against the
real plugin instance — no mocks of the plugin under test, only of its environment.
The TestKit is intentionally pure: no HttpClient, no Docker, no Testcontainers, no network. A plugin author can run
dotnet test on a laptop without internet.
Public surface
| Type | Purpose |
|---|---|
PluginHarness |
Loads a plugin DLL by path into a fresh collectible AssemblyLoadContext that resolves the plugin's dependencies from its own .deps.json. LoadFactory(path) returns the assembly's single IPluginFactory (it throws when there is none or more than one). LoadInstance<T>(path) creates the single public parameterless implementation of T, for a block or trigger plugin that has no IPluginFactory (pass its IWorkflowBlockFactory or ITriggerPluginFactory). StartAsync(path, config, host, instanceId?, ct) loads the factory, calls Create and StartAsync, and returns the running IReevePlugin. Disposing the harness (await using) stops and disposes every plugin it started and unloads its load contexts. |
FakePluginHostServices |
In-memory IPluginHostServices. The baseline members are recording fakes: AuditWriter (behind AuditSink), DeviceEventSink (behind DeviceEvents), InMemoryIssueRegistry (behind IssueRegistry), a memory cache and a data protector that returns its input. Gated capabilities are absent, as on a host that did not grant them: With<T>(impl) places one in the bag TryGet<T>() reads, and WithGrantedPermissions(...) and WithGrantedDeviceTypes(...) set what GrantedPermissions and GrantedDeviceTypes report. InMemoryObjectStorage is an IObjectStorage you can hand to the capability you place. Reset() clears everything between tests; dispose it after use. |
RecordingDeviceEventSink |
Records every call in arrival order: Discovered, Removed, StateChanges (the raw JSON overload), CanonicalStateChanges (the typed CanonicalDevice overload) and AvailabilityChanges. Reset() clears them. |
InMemoryIssueRegistry |
The host's issue registry. OpenIssues and ClearedIssues expose its state; AssertIssueRaised(code) and AssertIssueCleared(code) return the issue or throw. OpenIssuesBySubject, OpenIssuesFor(code) and a subject overload of both asserts cover per-subject issues. |
RecordingAuditWriter |
The plugin's IPluginAuditSink. Entries holds every RecordedAuditEntry (action, entity type and id, actor, metadata, time); AssertEntry(action) returns the first match or throws. |
There is no OAuth store in the TestKit: a plugin that uses a gated OAuth capability gets the fake implementation your
test places with With<T>.
Typical test shape
A test beside the scaffolded smoke test, once the plugin's TriggerResyncAsync reports devices (the scaffold's
reports none):
using Acme.MyWeatherInput;
using Reeve.PluginAbstractions;
using Reeve.PluginAuthoring.TestKit;
using Xunit;
namespace Acme.MyWeatherInput.Tests;
public sealed class MyWeatherInputTests
{
[Fact]
public async Task Reports_its_devices_after_a_resync()
{
var dllPath = PluginDllLocator.Resolve(typeof(MyWeatherInputFactory).Assembly);
await using var harness = new PluginHarness();
using var host = new FakePluginHostServices();
var plugin = await harness.StartAsync(
dllPath,
new Dictionary<string, string> { ["apiKey"] = "test-key" },
host);
var input = Assert.IsAssignableFrom<IInputPlugin>(plugin);
await input.TriggerResyncAsync(CancellationToken.None);
Assert.NotEmpty(host.DeviceEventSink.Discovered);
Assert.Equal(PluginHealthStatus.Healthy, plugin.GetHealth().Status);
}
}
PluginDllLocator is the internal helper the scaffolded tests/SmokeTests.cs defines, so every test in the project can
use it. It returns the plugin project's own bin/ copy, which sits beside the plugin's .deps.json and holds no SDK
assembly, so the plugin shares the test's Reeve.PluginAbstractions. Do not pass Assembly.Location instead: that is
the copy in the test's output folder, where the SDK assemblies the TestKit brings sit beside it, and the harness
resolves the plugin's dependencies from the folder it loads it from.
What the TestKit does not mock
- The plugin under test. You always load the real DLL through
PluginHarness, so the factory,Create,StartAsyncand theIPluginHostServicesinjection point are the production ones. - The host's own plugin load context. The harness's load context resolves every dependency from the plugin's folder;
the host shares the SDK assemblies with the plugin instead, and its pre-flight checks the references against the
host's copies. Run
reeve-plugindev validatefor that check. - The reload pipeline. Tests against reload behaviour belong in the host's integration tests, not the TestKit. The TestKit is for the offline unit-test loop.
Trust model
Native plugins are trusted in-process DLLs. The TestKit is a convenience surface for authors, not a sandbox —
FakePluginHostServices enforces no policy on what the plugin under test does with the services it receives. Authors
writing security-sensitive plugins (OAuth-mediated, credential-handling) should still assert on RecordingAuditWriter
that the expected audit entries are written at the expected transitions.