Repository navigation
Description
Motivation
While migrating an xUnit v3 test suite (.NET 11) from NSubstitute and Microsoft.Extensions.Diagnostics.Testing to full Compono alignment (Compono, Compono.XunitV3, Compono.TestDoubles, Compono.Logging, Compono.Options, all 1.3.2), four scenarios could not be expressed with Compono alone. Each one was hit by a real test, checked against the 1.3.2 documentation, and needed a workaround. No CMP diagnostics were raised, and several other candidate gaps turned out to be supported, so they are not listed.
1. No catch-all log capture across categories
- Need: a Generic Host test asserts that nothing was logged at Error level or above in any category, including framework and library categories (a scheduler, the hosting layer) that the test does not compose.
- Today:
Compono.LoggingcomposesILoggerandILogger<T>instances. There is noILoggerProvider,ILoggerFactoryorILoggingBuilderintegration, which the documentation describes as a v1 boundary. - Workaround: keep
AddFakeLogging()andFakeLogCollectorfor that one guard.
2. No metrics support
- Need: compose an
IMeterFactoryand assert counter, gauge and histogram measurements. - Today: there is no Compono package for metrics.
- Workaround: a hand-written test
IMeterFactoryregistered in a profile, plusMetricCollector<T>fromMicrosoft.Extensions.Diagnostics.Testing.
3. One Compose-family attribute per method, so no data rows
- Need: a table-driven theory whose rows vary composed configuration (option values, a clock instant) together with expected values.
- Today: only one Compose-family attribute is allowed per method. It cannot be combined with
[InlineData]or[MemberData], and[Compose<TProfile, TConfig>(...)]arguments must be attribute constants. - Cost: a 6-row table became 6 methods plus a shared assertion helper. Types that are not valid attribute arguments (such as
DateTimeOffset) need a string stand-in in the config record.
4. Runtime fixture values cannot reach a profile
- Need: compose a SUT whose dependencies depend on values created by an xUnit class or collection fixture, such as the connection string of a container-backed database or a broker address.
- Today: those values exist only at runtime and cannot be attribute constants. Profiles cannot receive fixture instances.
- Workaround: build the composer in the test body with
Composer.Create(...), register only the fixture-derived values, then callcomposer.Create<TSut>().
Together these force a mix of Compono and non-Compono test infrastructure and extra boilerplate in an otherwise fully composed suite.
Proposed solution
Each item is independent and can be delivered separately. The API names below are suggestions, not requirements.
1. Provider-backed log capture across categories
Add an extension to Compono.Logging that registers a capturing ILoggerProvider on the host's ILoggingBuilder, for example builder.Logging.AddComponoCapture().
- All categories write to one shared collector, including categories the test never composes.
- The collector exposes the recorded entries (level, category, message, exception, scope state) and simple filters, such as "any entry at or above
LogLevel.Error". - The existing composed
ILogger<T>capture keeps working, and both can read from the same collector.
2. A Compono.Metrics package
- Register a composed test
IMeterFactorythroughUseMetrics()(or similar), so meters created by the SUT are observable. - Provide collector helpers to read counter, gauge and histogram measurements by instrument name and tags. These can wrap
MetricCollector<T>. - Follow the same lifetime rules as the other integration packages, so the factory and its meters are disposed with the composition scope.
3. Data rows for composed theories
Either of these would remove the one-method-per-row split:
- Preferred: allow several
[Compose<TProfile, TConfig>(...)]attributes on one method, with one theory row per attribute. - Alternative: allow
[InlineData]or[MemberData]values to fill the non-composed parameters, with[Compose]filling the rest.
Also consider accepting non-constant config through a static member reference (like [MemberData]), so types such as DateTimeOffset need no string stand-in.
4. Fixture values available to profiles
Let a profile receive the xUnit class or collection fixture instances of the running test, for example through a profile constructor parameter or a context.Fixture<T>() call inside Configure.
- Fixture-derived values (connection strings, broker addresses) can then be registered in the profile.
- Tests can use
[Compose<TProfile>]for those SUTs and no longer need to callComposer.Create(...)in the test body. - Resolution should fail with a clear diagnostic when the requested fixture is not declared on the test class.
Priority
If these have to be prioritized, items 4 and 3 remove the most test boilerplate. Item 1 is a small, contained addition. Item 2 is the largest, since it is a new package.
Activity
ncipollina commentedon Nov 4, 2026
Feature intake complete. This issue stays open as the umbrella tracker. Each item is now its own sub-issue:
TestContext.Current.GetFixture<T>()inside a profileRegister<T>factory already reaches class and collection fixtures (friction:ValueTasksync-over-async, ambient xUnit coupling, untyped failure). Whether a Compono-native API is needed is still open.ILoggerFactoryuntil evidence). Looks feasible insideCompono.Loggingwith no new dependency.The API names in #161 and in the sub-issues are illustrative, not approved designs. The intake summary is in
docs/research/0036-issue-161-test-composition-gaps-intake.md(pending review).feat(metrics): add Compono.Metrics testing support (#179)
ncipollina commentedon Nov 12, 2026
Follow-up: adopted 1.4.0-preview.127, and all four workarounds are gone
I've migrated the suite that prompted this issue to
1.4.0-preview.127: all six packages, now includingCompono.Metrics. It's an xUnit v3 / .NET 11 GA worker service with 231 tests (unit, Testcontainers persistence and Generic Host). All four workarounds from the original report are removed, and the case count and assertions are unchanged. I checked every migrated test family by deliberately breaking the production code it covers and confirming the tests fail. I found no defects and no CMP diagnostics.LogCollector+builder.Logging.AddComponoCapture(collector)on a Generic HostAddFakeLoggingandMicrosoft.Extensions.Diagnostics.Testingremoved entirelyUseMetrics(),CapturingMeterFactory,Verify<long>(meter, instrument).WithValue(1).Once(),GetMeasurements<T>IMeterFactoryandMetricCollector<T>deleted[ComposeData<TProfile, TConfig>(nameof(Rows))]overTheoryDataRow[]withLabelDateTimeOffsetconfig with no string stand-inTestContext.Current.RequireFixture<T>()inside profileRegisterfactories[Compose<TProfile>]Remaining friction
None of these blocked us. They're ordered roughly by how much they cost us.
UseMetrics()depends on call order relative toUseGeneratedTestDoubles()([Feature]: Metrics testing: observe IMeterFactory-created instruments in composed tests #165).UseMetrics()came second, a generated double tookIMeterFactory, and 28 tests failed on the measurement assertions. The package's error message pointed us to the cause, but it's an easy trap in a shared base profile.IMeterFactoryregardless of order, or raise an error at configuration time when it's registered after a catch-all double provider.ComposeDatarow binding and access to the config ([Feature]: Composed theory data rows: vary profile configuration and expected values per row in one method #163).[Shared]and composed parameters. That's workable, but not obvious from the docs.TConfigback in the test body. One theory had to repeatdaysBeforeanddaysAfterin both the config record and the row values, so it could assert on them.TConfigparameter to bind to row element 0, or bind row values by parameter name.[Shared]disposables must be disposed by the test ([Feature]: Metrics testing: observe IMeterFactory-created instruments in composed tests #165).[Shared] IMeterFactoryneedsusing var _ = meters;.Compono.XunitV3dispose shared disposables when the test ends, which would remove that line throughout the suite.Asserting on one pass of a multi-pass test ([Feature]: Metrics testing: observe IMeterFactory-created instruments in composed tests #165).
ClearMeasurements()before the step under test. That works but hides the intent.using (meters.BeginCapture()) { ... }orVerify(...).Since(mark), would read better.InCategoryis an exact match ([Feature]: Host-wide log capture across all categories via Compono.Logging #164).MyApp.Jobs.*") is common in host-level guards, and today it needs aMatching(e => e.Category.StartsWith(...))predicate.InCategoryPrefixorInNamespacehelper.Profiles with constructor arguments in attributes ([Feature]: Runtime fixture values in composition profiles (xUnit class/collection fixtures) #162).
RequireFixtureremoved the connection-string parameter, but a profile that also takes interceptors needs an extra parameterless constructor to be named in[Compose<TProfile>]. The variants that do need interceptors must still be created in code withComposer.Create(...).ComposeDatasuppliesTConfig, would close that gap.Documentation: a short "migrating from
Microsoft.Extensions.Diagnostics.Testing" page would have shortened this work. It should mapAddFakeLogging/FakeLogCollectortoLogCollector/AddComponoCapture, andMetricCollector<T>toCapturingMeterFactory/Verify, and it should call out theUseMetrics()ordering.We're pinned to the preview until stable
1.4.0ships. Thanks for turning this around so quickly.feat(metrics,logging): address #161 1.4 dogfood follow-up findings (#181
ncipollina commentedon Nov 12, 2026
Thanks for the quick turnaround on #181. We adopted 1.4.0-preview.128 in our service's test suite (xUnit v3 JIT, Compono + Logging + Metrics + Options + TestDoubles + XunitV3). Everything from #181 behaved as documented:
ComponoMetricsOwnsMeterFactorytruein every test project, including one that only gets Compono transitively via ProjectReference. Order ofUseMetrics()vsUseGeneratedTestDoubles()no longer matters.TConfigviabuilder.Register(() => config)using var _ = meterFactory;lines.ClearMeasurements()Build: 0 warnings, no CMP diagnostics. 231/231 tests passing.
Remaining findings (preview.128)
Missing
UseMetrics()error isn't actionable. Leaving outUseMetrics()produces:It's accurate, but since Compono already knows Compono.Metrics owns
IMeterFactory(that's whatComponoMetricsOwnsMeterFactorydrives), a hint like "IMeterFactory is provided by Compono.Metrics; callUseMetrics()" would save a lookup. The same idea could apply toILogger→UseLogging().Reading the row's
TConfigback still needs boilerplate. Each profile has to addbuilder.Register(() => config)by hand, and the test has to declare an extra parameter. An opt-in that exposes the row'sTConfigautomatically would remove that. This is minor.Is
Share<IMeterFactory>()still required alongsideUseMetrics()? We still call both. IfUseMetrics()already shares the factory per graph, a note in the docs (or making it do so) would let us drop the extra line.Failed
ComposeDatarows collapse the theory count. When composition fails for a row (e.g. the missingUseMetrics()case above), the theory is reported once instead of once per row. Our Application test count went from 49 to 42 in that run. This is harmless but surprising when you compare counts.No mismatches between the docs and the behavior beyond the above.
docs(metrics,logging,xunitv3): address #161 preview.128 dogfood follo…
ncipollina commentedon Nov 12, 2026
All four items are delivered and ship in 1.4.0:
RequireFixture<TFixture>())ComposeData)AddComponoCapture()/LogCollector)Compono.Metrics)The dogfood follow-ups from preview.127 and preview.128 were addressed in #181 and #183. Closing as complete.