monica-unit-testing
Skill18 starsChanged 7 months agoMITView on GitHub
Create, migrate, or review Monica framework tests and shared testing infrastructure, including host-owned scenarios, raw BuildingBlock fixtures, Roslyn source-generator tests, result assertions, and isolation.
In this repository34 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- monica-application-building-block-developmentSkill
- monica-application-microserviceSkill
- monica-application-modular-monolithSkill
- monica-applicationSkill
- monica-application-ui-developmentSkill
- monica-application-uiSkill
- monica-application-unit-testingSkill
- monica-architectureSkill
- monica-coding-standardsSkill
- monica-contributionSkill
- monica-developmentSkill
- monica-docs-authoringSkill
- monica-frameworkSkill
- monica-guideSkill
- monica-infra-aiSkill
- monica-infra-configurationSkill
- monica-infra-hostingSkill
- monica-infra-jobsSkill
- monica-infra-messagingSkill
- monica-infra-observabilitySkill
- monica-infra-persistenceSkill
- monica-infra-uiSkill
- monica-infra-webSkill
- monica-opentelemetrySkill
- monica-requirement-designSkill
- monica-third-party-module-developmentSkill
- monica-troubleshootingSkill
- monica-ui-auditSkill
- monica-ui-bridge-debugSkill
- monica-ui-designSkill
- monica-ui-developmentSkill
- monica-ui-localizationSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
28 rules. About 0 are common, 10 are distinctive, and 18 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
18
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 8
Use Monica.Testing as the shared toolkit and keep runnable framework tests under tests/Test.Monica.*.
- Very specific: line 12
Read <project-root>/tests/README.md for the current project layout and execution rules.
- Very specific: line 19
Put reusable assertions, host helpers, and deterministic boundary doubles in Monica.Testing.
- Distinctive: line 20
Prefer public-surface coverage: module registrations, facades, public models and abstractions, stable providers, and observable side …
- Distinctive: line 21
Use the repository test runner or the relevant test project.
- Very specific: line 25
Use MonicaTestApplicationFactory<TDiscoveryAnchor> when the test depends on real Monica composition.
- Very specific: line 28
Use ConfigureHost(WebApplicationBuilder) for host configuration and environment inputs.
- Very specific: line 29
Use ConfigureServices(IServiceCollection) for stable test-boundary registrations shared by every scenario produced by that factory.
- Very specific: line 30
Call CreateAsync(...) for each test scenario.
- Very specific: line 32
Call MonicaTestApplication.CreateScope(...) only to create a normal child scope.
- Very specific: line 35
Do not copy service descriptors into another root provider, share one MonicaApplication across providers, or emulate per-scope registration …
- Distinctive: line 49
Use it only when all collaborators are deliberately supplied and the assertion does not depend on:
- Very specific: line 57
Use the host-owned scenario model for any of those behaviors.
- Very specific: line 61
Test source generators with raw Roslyn inputs under a dedicated tests/Test.Monica.{GeneratorProject} project.
- Very specific: line 64
Create all source text in memory, provide explicit metadata references, and run CSharpGeneratorDriver with the same language version the …
- Distinctive: line 66
Run the same driver again with identical inputs and assert byte-identical generated sources and diagnostics.
- Distinctive: line 67
Verify generator execution does not create or mutate files.
- Very specific: line 69
When a published request uses a custom IRemoteResultEnvelope<TSelf>, test that CreateRemoteFailure returns a valid constructor-initialized …
- Very specific: line 77
Test folders mirror source folders such as Modules/, Facades/, Providers/, Services/, Pages/, and Components/.
- Distinctive: line 82
Test module behavior through registration extensions, dependencies, resulting options, or DI-visible registrations rather than static …
- Distinctive: line 84
Avoid real network, uncontrolled persistence, sleeps, random inputs, and untracked machine state.
- Very specific: line 85
Keep InternalsVisibleTo exceptional and scoped to the corresponding runnable test project.
- Distinctive: line 86
Run independent test scenarios in parallel by default.
- Very specific: line 99
Read references/standards.md for stable boundary and isolation rules.
- Very specific: line 100
Read references/samples.md when selecting an existing framework sample.
- Very specific: line 101
Use $monica-application-unit-testing for Monica-based business-service tests.
- Distinctive: line 106
Keep build/test processes sharing outputs sequential.
- Distinctive: line 107
Run the relevant runnable test project and the repository's default non-UI gate when required.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Monica Unit Testing
Use Monica.Testing as the shared toolkit and keep runnable framework tests under tests/Test.Monica.*. Choose the smallest test boundary that proves the behavior without misrepresenting Monica's activation or host lifecycle.
Workflow
- Read
<project-root>/tests/README.mdfor the current project layout and execution rules. - Classify the test before choosing infrastructure:
- Pure logic: construct the value or service directly.
- Raw Building Block collaboration: use
BuildingBlockFixture<TBuildingBlock>and accept its activation limits. - Module wiring, options, conventional registration, proxies, hosted lifecycle, or cross-scope behavior: create a full host with
MonicaTestApplicationFactory<TDiscoveryAnchor>. - Blazor behavior contract: use bUnit in the runnable UI test project only when the user explicitly requests UI testing or UI test additions.
- Roslyn source-generator semantics: build an in-memory
CSharpCompilationand run the generator throughGeneratorDriver.
- Put reusable assertions, host helpers, and deterministic boundary doubles in
Monica.Testing; keep scenario-specific data and doubles in the runnable test project. - Prefer public-surface coverage: module registrations, facades, public models and abstractions, stable providers, and observable side effects.
- Use the repository test runner or the relevant test project. Keep processes that share build outputs sequential.
Host-Owned Scenarios
Use MonicaTestApplicationFactory<TDiscoveryAnchor> when the test depends on real Monica composition.
- Derive a project factory and implement
ConfigureMonica(IMonicaBuilder)with the production module graph needed by the scenario. - Use
ConfigureHost(WebApplicationBuilder)for host configuration and environment inputs. - Use
ConfigureServices(IServiceCollection)for stable test-boundary registrations shared by every scenario produced by that factory. Call the base implementation first unless the scenario intentionally replaces all standard seams. - Call
CreateAsync(...)for each test scenario. Every call builds and starts a complete host with its ownMonicaApplication, module graph, singleton services, logger ownership, and disposal boundary. - Pass scenario-specific seam replacements to
CreateAsync(Action<ISeamReplacementBuilder>?). The callback changes registrations before the host is built. - Call
MonicaTestApplication.CreateScope(...)only to create a normal child scope. A built service provider is immutable; scope creation never replaces registrations. - Dispose the
MonicaTestApplicationafter the scenario, even when several scopes are used within that scenario.
Do not copy service descriptors into another root provider, share one MonicaApplication across providers, or emulate per-scope registration replacement.
Persistence Scenarios
Keep production context/provider registration. UseTestDatabase overrides options and keeps one database per scenario/context type, with fresh scoped connections. Arrange with application.SeedAsync<TContext,TResult> and an explicit save; act through application.ExecuteAsync and the real IExecutionPipeline; verify in application.VerifyAsync<TContext>. Do not add synthetic save loops or clear trackers to repair tests.
Default seams retain real audit policy; replace TimeProvider/current-user/ID inputs. SeedAsync suppresses entity projections. Test [Outbox] publishing through the real scoped EventBus gateway, inspect committed row snapshots separately from delivery, and explicitly call DrainOutboxAsync<TContext>. Replace IEventTransport, not IDistributedEventBus, for provider recording. Include rollback after an early flush for escaping exceptions and explicit abort, commit after returned failures or handled exceptions, generated-key capture, immutable payloads, retry identity, Inbox consumer uniqueness, and fresh-scope retries.
When a handler host has multiple write contexts, put [ExecutionTransaction(ExecutionTransactionMode.Automatic, DbContextTypes = new[] { typeof(PrimaryDbContext), typeof(ParticipantDbContext) })] on its concrete execution method and test the real receive pipeline. The selected primary context owns Inbox and Outbox rows; verify its final flush after later participants stage projections. Follow the persistence transaction contract for selection and explicit execution features.
Raw Building Block Fast Path
BuildingBlockFixture<TBuildingBlock> is an explicitly raw fast-path harness. It creates a small Microsoft DI container, activates the target, and initializes Monica's cached-service-provider accessor where applicable.
Use it only when all collaborators are deliberately supplied and the assertion does not depend on:
- Monica module composition or options binding
- conventional type discovery and registration
- dynamic proxies or interceptors
- hosted-service startup and shutdown
- host-owned singleton or logging isolation
Use the host-owned scenario model for any of those behaviors. Do not introduce another application-service-specific fixture; ApplicationServiceFixture<THandler> is not part of the testing model.
Roslyn Generator Boundary
Test source generators with raw Roslyn inputs under a dedicated tests/Test.Monica.{GeneratorProject} project.
- Reference the generator as a normal test dependency so the test can instantiate its public
IIncrementalGeneratortypes. Do not rely on MSBuild analyzer execution for semantic generator tests. - Create all source text in memory, provide explicit metadata references, and run
CSharpGeneratorDriverwith the same language version the scenario requires. - Assert generator diagnostics, generated hint names and source, and the diagnostics of the updated output compilation.
- Run the same driver again with identical inputs and assert byte-identical generated sources and diagnostics. This protects incremental determinism.
- Verify generator execution does not create or mutate files. File export, package imports, and MSBuild target ordering belong in separate integration tests only when those build surfaces are intentionally under test.
- For request-owned Web API generation, cover the public contract matrix: route, verb, binding, operation naming, cancellation, result shapes, published-API namespace selection, local-only HTTP exclusion, duplicate or invalid declarations, and same-compilation client/controller availability.
- When a published request uses a custom
IRemoteResultEnvelope<TSelf>, test thatCreateRemoteFailurereturns a valid constructor-initialized envelope and that cancellation is propagated rather than projected as a failure result.
Required Conventions
- Shared toolkit:
Monica.Testing/Monica.Testing.csproj - Runnable project:
tests/Test.Monica.{ProjectName}/ - Test class:
{TypeName}Tests - Test method:
Method_WhenCondition_ShouldExpectation - Test folders mirror source folders such as
Modules/,Facades/,Providers/,Services/,Pages/, andComponents/.
Monica-Specific Rules
- Assert
Result<T>explicitly. Facade tests coverStatus,Message, andData; successful string paths verify data and message separately. Cover Created as success, permitted null payloads, failure metadata forwarding, and meaningful failure reports. Use the Core runtime contracts and generator-project compilation probes for the explicit result API. - Test module behavior through registration extensions, dependencies, resulting options, or DI-visible registrations rather than static tables alone.
- Supply doubles for external dependencies. Resolve application services, domain services, repositories, and options from the scenario host.
- Avoid real network, uncontrolled persistence, sleeps, random inputs, and untracked machine state.
- Keep
InternalsVisibleToexceptional and scoped to the corresponding runnable test project. - Run independent test scenarios in parallel by default. Serialize only tests that name and document a genuinely shared external resource.
Default Stack
- xUnit v3
- AwesomeAssertions
- NSubstitute with its analyzer
- coverlet.collector
- bUnit in UI test projects only
- Microsoft.CodeAnalysis.CSharp in source-generator test projects only
References
- Read
references/standards.mdfor stable boundary and isolation rules. - Read
references/samples.mdwhen selecting an existing framework sample. - Use
$monica-application-unit-testingfor Monica-based business-service tests.
Validation
- Match path syntax to the SDK process actually running.
- Keep build/test processes sharing outputs sequential.
- Run the relevant runnable test project and the repository's default non-UI gate when required. UI projects run only on explicit user request.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

