Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `DependencyModules.Testing` depends on `DependencyModules.Runtime` and on
`Microsoft.Extensions.DependencyInjection`: version 8.0.1 for `net8.0` and version 10.0.0 for
`net10.0`. Before, it depended on `Microsoft.Extensions.DependencyInjection.Abstractions` only.
- The unit tests are in two projects. `tests/DependencyModules.Specs` runs on VerificationGlue.Tests
and has the tests of the runtime, the source generator, the code fixes, the public API, and
`DependencyModules.Testing`. `scripts/test-verificationglue.sh` runs it. The tests of the xUnit
and NUnit integrations stay on xUnit, in `tests/DependencyModules.xUnit.Tests`, which was
`tests/DependencyModules.Tests`. `scripts/test-xunit.sh` runs them on each `xunit.v3` major. No
package changes. (#136, #137, #138, #139, #140)

## [1.7.0] - 2026-09-25

Expand Down
22 changes: 21 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,27 @@ dotnet build DependencyModules.sln --configuration Release

The `restore` step needs the `test-tools` feed in `NuGet.config`, which has the Microsoft.Testing.Platform 3 preview that VerificationGlue.Tests uses. No shipping package references VerificationGlue.

The unit tests are in two projects while they move to VerificationGlue.Tests. `tests/DependencyModules.Specs` has the `RuntimeTests`, `ApiTests` and `GeneratorTests` folders. `tests/DependencyModules.Tests` has the other folders. Both projects compile the test harness in `tests/DependencyModules.Specs/Infrastructure`. Each project reads the snapshots in its own `Snapshots` folder.
### The test suites

| Project | Runner | Target frameworks | What it tests |
| --- | --- | --- | --- |
| `tests/DependencyModules.Specs` | VerificationGlue.Tests | `net10.0` | The runtime, the source generator, the code fixes, the public API, and DependencyModules.Testing |
| `tests/DependencyModules.xUnit.Tests` | xUnit | `net8.0`, `net10.0` | DependencyModules.xUnit, DependencyModules.xUnit4, and DependencyModules.NUnit |
| `integ-tests/SutProject.Tests` | xUnit | `net8.0`, `net10.0` | The generated code of a real project, through DependencyModules.xUnit |
| `integ-tests/web/WebApiApp.Tests` | xUnit | `net8.0`, `net10.0` | The generated code of an ASP.NET Core application, through DependencyModules.xUnit |
| `integ-tests/SutProject.NUnitTests` | NUnit | `net8.0`, `net10.0` | The generated code of a real project, through DependencyModules.NUnit |

Put a new unit test in `tests/DependencyModules.Specs`. Its tests use `[VerifyTest]` and `Verify(...)`. When a check fails, the message shows the expression and the value of each part of it. The project has the test harness in `Infrastructure` and the snapshots in `Snapshots`.

Put a test in `tests/DependencyModules.xUnit.Tests` only when it tests the xUnit or NUnit integration. These tests use `[ModuleTest]` from DependencyModules.xUnit, or they call the `xunit.v3` extensibility types directly. Thus they must run on xUnit, and they run on each `xunit.v3` major. The project also targets `net8.0`, because the integration packages have a `net8.0` build.

To run `tests/DependencyModules.Specs`, use `./scripts/test-verificationglue.sh`. To run one of the other projects with `xunit.v3` version 3, use `dotnet test`:

```shell
dotnet test tests/DependencyModules.xUnit.Tests --configuration Release
```

`./scripts/coverage.sh` runs all five projects. `./scripts/test-xunit.sh 4` runs the xUnit projects and `tests/DependencyModules.Specs` with `xunit.v3` version 4.

To run all tests with code coverage, use the coverage script. The script writes the report to `artifacts/coverage`. If you give a percentage, the script fails when the line coverage is less than that value.

Expand Down
2 changes: 1 addition & 1 deletion DependencyModules.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApiApp.Tests", "integ-te
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{F4DC9AA2-7F61-4DEE-A7D1-2BCDBEEFD1C5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DependencyModules.Tests", "tests\DependencyModules.Tests\DependencyModules.Tests.csproj", "{1AFFBCCF-FD6E-4232-9DC7-40FE2784ECD1}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DependencyModules.xUnit.Tests", "tests\DependencyModules.xUnit.Tests\DependencyModules.xUnit.Tests.csproj", "{1AFFBCCF-FD6E-4232-9DC7-40FE2784ECD1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{2E4BAA8C-195F-490B-B9F9-57194B08CD12}"
EndProject
Expand Down
2 changes: 1 addition & 1 deletion scripts/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mkdir -p "${OUT}" "${RAW}"
# Every suite contributes: the integration projects exercise a great deal of the generator
# that the unit tests never reach directly.
PROJECTS=(
"tests/DependencyModules.Tests/DependencyModules.Tests.csproj"
"tests/DependencyModules.xUnit.Tests/DependencyModules.xUnit.Tests.csproj"
"integ-tests/SutProject.Tests/SutProject.Tests.csproj"
"integ-tests/SutProject.NUnitTests/SutProject.NUnitTests.csproj"
"integ-tests/web/WebApiApp.Tests/WebApiApp.Tests.csproj"
Expand Down
2 changes: 1 addition & 1 deletion scripts/test-xunit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if [ -n "${2:-}" ]; then PROPERTIES+=("-p:XunitV3Version=$2"); fi
if [ -n "${3:-}" ]; then PROPERTIES+=("-p:XunitRunnerVersion=$3"); fi

PROJECTS=(
"tests/DependencyModules.Tests/DependencyModules.Tests.csproj"
"tests/DependencyModules.xUnit.Tests/DependencyModules.xUnit.Tests.csproj"
"integ-tests/SutProject.Tests/SutProject.Tests.csproj"
"integ-tests/web/WebApiApp.Tests/WebApiApp.Tests.csproj"
)
Expand Down
4 changes: 2 additions & 2 deletions tests/DependencyModules.Specs/Infrastructure/Require.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace DependencyModules.Tests.Infrastructure;

/// <summary>
/// The harness checks. They throw a plain exception, which fails the test on any runner, because
/// the harness is compiled into an xUnit project and a VerificationGlue.Tests project.
/// The harness checks. They throw a plain exception, which fails the test on any runner, so the
/// harness does not depend on a test framework.
/// </summary>
public static class Require
{
Expand Down
4 changes: 1 addition & 3 deletions tests/DependencyModules.Specs/Infrastructure/Snapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ namespace DependencyModules.Tests.Infrastructure;
/// unintended changes to generated output show up as a reviewable diff.
///
/// To accept new output, re-run the tests with UPDATE_SNAPSHOTS=1:
/// UPDATE_SNAPSHOTS=1 dotnet test tests/DependencyModules.Tests
/// UPDATE_SNAPSHOTS=1 scripts/test-verificationglue.sh
/// and review the resulting changes under the Snapshots folder of each project. Each project
/// reads the snapshots of its own folder.
/// and review the resulting changes under tests/DependencyModules.Specs/Snapshots.
///
/// Snapshots are read from the build output, where they are copied by the project file.
/// [CallerFilePath] is deliberately not used to locate them: deterministic builds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<!--
The tests of the xUnit and NUnit integrations. They stay on xUnit because they use
[ModuleTest] from DependencyModules.xUnit or the xunit.v3 extensibility types, and they run
on both xunit.v3 majors through scripts/test-xunit.sh. DependencyModules.xUnit,
DependencyModules.xUnit4 and DependencyModules.NUnit ship a net8.0 build, so this project
keeps net8.0. The other unit tests are in tests/DependencyModules.Specs.
-->
<PropertyGroup>
<TargetFrameworks>$(LibraryTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -14,37 +21,19 @@

<ItemGroup>
<ProjectReference Include="..\..\src\DependencyModules.Runtime\DependencyModules.Runtime.csproj"/>
<!-- Referenced as a library, not an analyzer: these tests drive the generator directly. -->
<ProjectReference Include="..\..\src\DependencyModules.SourceGenerator\DependencyModules.SourceGenerator.csproj"
OutputItemType="Analyzer" ReferenceOutputAssembly="true"/>
<ProjectReference Include="..\..\src\DependencyModules.CodeFixes\DependencyModules.CodeFixes.csproj"/>
OutputItemType="Analyzer" ReferenceOutputAssembly="false"/>
<ProjectReference Include="..\..\src\$(DependencyModulesXunitProject)\$(DependencyModulesXunitProject).csproj"/>
<!--
Referenced for the public API snapshot only. This project's own tests run on xUnit; the
NUnit integration is exercised end to end by integ-tests/SutProject.NUnitTests.
-->
<!-- NUnitTests drive the NUnit integration's test-case building directly, from xUnit. -->
<ProjectReference Include="..\..\src\DependencyModules.NUnit\DependencyModules.NUnit.csproj"/>
<ProjectReference Include="..\..\src\DependencyModules.NSubstitute\DependencyModules.NSubstitute.csproj"/>
<ProjectReference Include="..\..\src\DependencyModules.Moq\DependencyModules.Moq.csproj"/>
<ProjectReference Include="..\..\src\DependencyModules.FakeItEasy\DependencyModules.FakeItEasy.csproj"/>
</ItemGroup>

<!--
The test harness lives in tests/DependencyModules.Specs and is compiled into both projects
while the test folders move there one at a time. It uses no test framework.
-->
<ItemGroup>
<Compile Include="..\DependencyModules.Specs\Infrastructure\**\*.cs" LinkBase="Infrastructure"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="PublicApiGenerator" Version="11.5.4"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.10.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitRunnerVersion)">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -66,20 +55,4 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0"/>
</ItemGroup>

<!--
Snapshots are read from the build output so the tests do not depend on source paths,
which deterministic builds rewrite to /_/... The source location is injected separately
and used only when UPDATE_SNAPSHOTS=1.
-->
<ItemGroup>
<Content Include="Snapshots\**\*.verified.txt" CopyToOutputDirectory="PreserveNewest" LinkBase="Snapshots"/>
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>SnapshotDirectory</_Parameter1>
<_Parameter2>$(MSBuildProjectDirectory)/Snapshots</_Parameter2>
</AssemblyAttribute>
</ItemGroup>

</Project>
Loading