Skip to content

Restructure tests and reach full coverage - #23

Merged
tillig merged 3 commits into
developfrom
feature/restructure-tests
Aug 14, 2026
Merged

Restructure tests and reach full coverage#23
tillig merged 3 commits into
developfrom
feature/restructure-tests

Conversation

@tillig

@tillig tillig commented Aug 14, 2026

Copy link
Copy Markdown
Member

Test-only change. No production source is touched.

Conventions applied

  • *TestFixture*Tests for every file and class.
  • Unit test methods use MethodUnderTest_Scenario with a single underscore.
  • Test methods sorted alphabetically within each class.
  • All // arrange / // act / // assert comments removed.
  • No XML docs on test methods. The two private nested helpers keep a one-line summary, since why they exist is not obvious from their names.

Layout

End-to-end scenario tests moved to an Integration namespace, where the method name is just the scenario being verified. Per-class unit tests stay at the root, next to the class they cover.

AttributedMetadataModuleTests.cs      AttachToComponentRegistration_*
AutofacAttributeExtensionsTests.cs    WithAttributedMetadata_*
MetadataHelperTests.cs                GetMetadata_* / GetProperties_*
MetadataModuleTests.cs                ContainerBuilder_* / RegisterType_* / RegisterAttributedType_*
Integration/
  AttributedMetadataModuleTests.cs    MetadataFromMultipleAttributes, MetadataFromSingleAttribute
  CombinationalWeakTypedAttributeTests.cs
  MetadataModuleTests.cs              MetadataFromGenericRegistration, MetadataFromTypeOfRegistration, ...
  MetadataProviderTests.cs            MetadataFromProviderStrongTyped, MetadataFromProviderWeakTyped
  StrongTypedAttributeTests.cs        MetadataFromTypedAttributes
  WeakTypedAttributeTests.cs          MetadataFromWeakTypedAttributes

Coverage

Went from 79.71% lines / 47 of 50 branches to 100% lines and 100% branches, 40 tests up from 22.

New tests cover the argument guards on MetadataHelper, MetadataModule<,> and AutofacAttributeExtensions (one test per guard, no parameterization, asserting only the exception type), plus a direct test of the IMetadataProvider path in GetProperties.

Two of the branch gaps were worth understanding rather than papering over:

  • AutofacAttributeExtensions.cs had a half-covered branch on the typed-metadata scanning overload. It was the compiler's cached-delegate initialization, only reachable by invoking that overload more than once per closed generic. Covered by giving that overload its own positive unit test, which it was missing anyway.
  • MetadataHelper.cs had a half-covered branch in the property filter: no test ever passed an attribute with a non-readable property. Covered by GetProperties_WriteOnlyProperty, which pins the documented rule that only publicly readable properties become metadata.

Also

Renamed the ScenarioTypes/MetadataProviderScenario folder to MetadataProviderScenarioTypes so it matches the namespace its files already declared. Folder-only move, no code change. Happy to drop this if you'd rather keep the PR strictly to the test restructure.

Verification

dotnet msbuild ./default.proj clean: 40/40 tests pass on net10.0 and net8.0, zero warnings, packages build. dotnet format --verify-no-changes clean. Verified programmatically that no Fixture names or arrange/act/assert comments remain and that every class's test methods are in alphabetical order.

Applies the C# test conventions: fixtures renamed from *TestFixture to
*Tests, unit test methods named MethodUnderTest_Scenario, methods sorted
alphabetically, and arrange/act/assert comments removed.

End-to-end scenario tests move into an Integration namespace, where the
method name is just the scenario being verified. Per-class unit tests stay
at the root next to the class they cover.

Also renames the MetadataProviderScenario folder to match the namespace its
files already declared.

Adds tests for the previously uncovered argument guards on MetadataHelper,
MetadataModule and AutofacAttributeExtensions, a direct test of the
IMetadataProvider path, and one for the documented rule that write-only
attribute properties contribute no metadata. Line and branch coverage are
now both 100%.
@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (bda2dcd) to head (11b0891).

Additional details and impacted files
@@              Coverage Diff              @@
##           develop       #23       +/-   ##
=============================================
+ Coverage    56.52%   100.00%   +43.47%     
=============================================
  Files            4         4               
  Lines           69        69               
  Branches        24        24               
=============================================
+ Hits            39        69       +30     
+ Misses          14         0       -14     
+ Partials        16         0       -16     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

tillig added 2 commits August 14, 2026 14:50
Nests single-use support types as private classes in the test that uses
them: the nested scope component and all four metadata modules.

Merges duplicate support types. The Name-only and Name-plus-Age metadata
views each existed twice under different names, and three separate
attributes carried a single string property. These become INameMetadata,
INameAndAgeMetadata, NameMetadataAttribute, AgeMetadataAttribute and
NameAndAgeMetadataAttribute.

Flattens ScenarioTypes to a single namespace, which removes the
MetadataModuleScenarioDiscoveryTargets name. Service interfaces stay
distinct per scenario because the assembly scanning tests filter on them
and assert exact counts.

Merges the three single-test assembly scanning classes into
Integration.AssemblyScanningTests.

Scenario support files drop from 32 to 20. Coverage stays at 100% of lines
and branches.
The old names described the test that used a type rather than the type
itself, so ScenarioTypes becomes Stubs and every name now says what the
thing is:

- Metadata views: IDataView, IDataAndCountView, DataView, ProvidedDataView.
- Attributes: DataAttribute and CountAttribute are reflected into the
  metadata dictionary; DataAndCountAttribute implements its view so the
  typed discovery overload can find it; ProvidedDataAttribute supplies its
  own dictionary.
- Components: Reflected, Combined, Typed, Programmatic and Provided, each
  named for how its metadata arrives.

The weak/strong typed wording is gone. It had no counterpart in the
implementation, so the two discovery modes are now described where they
live: the untyped GetMetadata overload takes every metadata attribute,
while the typed overload takes only attributes assignable to a given view.
Each stub carries an XML summary saying what it is and why it exists.

Payload properties are Data and Count rather than Name and Age so they read
as arbitrary values and not as domain concepts.

Coverage stays at 100% of lines and branches.
@tillig
tillig merged commit ee34b93 into develop Aug 14, 2026
12 checks passed
@tillig
tillig deleted the feature/restructure-tests branch August 14, 2026 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant