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
7 changes: 7 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
"version": 1,
"isRoot": true,
"tools": {
"dotnet-reportgenerator-globaltool": {
"version": "5.5.11",
"commands": [
"reportgenerator"
],
"rollForward": false
},
"dotnet-validate": {
"version": "0.0.1-preview.582",
"commands": [
Expand Down
2 changes: 1 addition & 1 deletion .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ coverage:
project:
default:
if_not_found: failure
target: 95%
target: 90%
1 change: 0 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,3 @@ updates:
- dependency-name: "Microsoft.AspNetCore.Mvc.Testing"
- dependency-name: "Microsoft.OpenApi"
- dependency-name: "Microsoft.OpenApi.YamlReader"
- dependency-name: "xunit"
8 changes: 6 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ It targets the currently released and supported versions of .NET.
./build.ps1
```

This runs `dotnet pack` followed by `dotnet test`.
This restores the .NET tools, runs `dotnet pack` followed by `dotnet test`, then generates code coverage reports with ReportGenerator.

**Build only:**

Expand All @@ -41,7 +41,7 @@ dotnet test test/Swashbuckle.AspNetCore.IntegrationTests/
**Run a single test:**

```bash
dotnet test test/Swashbuckle.AspNetCore.SwaggerGen.Test/ --filter "FullyQualifiedName~MethodName"
dotnet test test/Swashbuckle.AspNetCore.SwaggerGen.Test/ --filter-method "*MethodName"
```

**Restore .NET tools:**
Expand Down Expand Up @@ -81,6 +81,10 @@ When snapshot-based tests fail due to intentional changes, update snapshots by r

### Test structure (`test/`)

Tests use xUnit v3 running on [Microsoft Testing Platform](https://learn.microsoft.com/dotnet/core/testing/microsoft-testing-platform-intro)
(configured via the `test` section of `global.json`), with code coverage collected by `Microsoft.Testing.Extensions.CodeCoverage`
using the settings in `tests.runsettings`. Coverage reports are written to `artifacts/coverage/{project}/`.

- `Swashbuckle.AspNetCore.SwaggerGen.Test` — unit tests for schema and swagger generation; uses xUnit v3 and Verify for snapshot testing; snapshots stored under `snapshots/{tfm}/`.
- `Swashbuckle.AspNetCore.IntegrationTests` — end-to-end tests running real `WebApplication` instances; also uses Verify snapshots and Playwright for UI tests.
- `WebSites/` — sample ASP.NET Core apps used as test fixtures (Basic, MinimalApp, MultipleVersions, OAuth2Integration, etc.).
Expand Down
8 changes: 2 additions & 6 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,8 @@
<PublicSign>true</PublicSign>
</PropertyGroup>
<PropertyGroup>
<CoverletOutputFormat>cobertura,json</CoverletOutputFormat>
<CoverletOutputFormat Condition=" '$(GITHUB_ACTIONS)' != '' ">$(CoverletOutputFormat),opencover</CoverletOutputFormat>
<Exclude>[System.*]*,[*.Test*]*,[xunit.*]*</Exclude>
<ExcludeByAttribute>GeneratedCodeAttribute</ExcludeByAttribute>
<Include>[Swashbuckle.*]*</Include>
<Threshold></Threshold>
<CoverageFormat>cobertura</CoverageFormat>
<CoverageRunSettings>$(MSBuildThisFileDirectory)tests.runsettings</CoverageRunSettings>
</PropertyGroup>
<PropertyGroup>
<IsDependabotJob Condition=" '$(GITHUB_ACTIONS)' == 'true' AND '$(DEPENDABOT_JOB_ID)' != '' ">true</IsDependabotJob>
Expand Down
42 changes: 20 additions & 22 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,30 @@
<CollectCoverage>true</CollectCoverage>
</PropertyGroup>
<ItemGroup Condition=" '$(IsTestProject)' == 'true' ">
<PackageReference Include="coverlet.msbuild" PrivateAssets="All" />
<PackageReference Include="GitHubActionsTestLogger" PrivateAssets="All" />
<PackageReference Include="JunitXml.TestLogger" PrivateAssets="All" />
<PackageReference Include="ReportGenerator" PrivateAssets="All" />
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" PrivateAssets="All" />
</ItemGroup>
<PropertyGroup Condition=" '$(CollectCoverage)' == 'true' ">
<CoverletReportsPath>$([System.IO.Path]::Combine($(ArtifactsPath), 'coverage', '$(MSBuildProjectName)'))</CoverletReportsPath>
<CoverletOutput>$([System.IO.Path]::Combine('$(CoverletReportsPath)', 'coverage'))</CoverletOutput>
<ReportGeneratorOutputMarkdown Condition=" '$(ReportGeneratorOutputMarkdown)' == '' AND '$(GITHUB_SHA)' != '' ">true</ReportGeneratorOutputMarkdown>
<ReportGeneratorReportTypes>HTML</ReportGeneratorReportTypes>
<ReportGeneratorReportTypes Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' ">$(ReportGeneratorReportTypes);MarkdownSummaryGitHub</ReportGeneratorReportTypes>
<ReportGeneratorMarkdownSummary>$([System.IO.Path]::Combine($(CoverletReportsPath), 'SummaryGithub.md'))</ReportGeneratorMarkdownSummary>
<CoverageOutputPath>$([MSBuild]::ValueOrDefault('$(CoverageOutputPath)', '$([System.IO.Path]::Combine($(ArtifactsPath), 'coverage'))'))</CoverageOutputPath>
<CoverageOutput>$([MSBuild]::ValueOrDefault('$(CoverageOutput)', '$([System.IO.Path]::Combine($(CoverageOutputPath), '$(MSBuildProjectName)', 'coverage.$(TargetFramework).xml'))'))</CoverageOutput>
</PropertyGroup>
<Target Name="_UpdateTestPlatformProperties" BeforeTargets="_MTPAddArguments;InvokeTestingPlatform" Condition=" '$(IsTestProject)' == 'true' ">
<PropertyGroup Condition=" '$(CollectCoverage)' == 'true' ">
<_TestingPlatformCommandLineArguments>$(_TestingPlatformCommandLineArguments) --coverage</_TestingPlatformCommandLineArguments>
<_TestingPlatformCommandLineArguments Condition=" '$(CoverageFormat)' != '' ">$(_TestingPlatformCommandLineArguments) --coverage-output-format %22$(CoverageFormat)%22</_TestingPlatformCommandLineArguments>
<_TestingPlatformCommandLineArguments Condition=" '$(CoverageOutput)' != '' ">$(_TestingPlatformCommandLineArguments) --coverage-output %22$(CoverageOutput)%22</_TestingPlatformCommandLineArguments>
<_TestingPlatformCommandLineArguments Condition=" '$(CoverageRunSettings)' != '' ">$(_TestingPlatformCommandLineArguments) --coverage-settings %22$(CoverageRunSettings)%22</_TestingPlatformCommandLineArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(GITHUB_ACTIONS)' == 'true' ">
<_TestingPlatformCommandLineArguments>$(_TestingPlatformCommandLineArguments) --report-github</_TestingPlatformCommandLineArguments>
<_TestingPlatformCommandLineArguments>$(_TestingPlatformCommandLineArguments) --report-github-summary-include-passed false</_TestingPlatformCommandLineArguments>
<_TestingPlatformCommandLineArguments>$(_TestingPlatformCommandLineArguments) --report-xunit-junit</_TestingPlatformCommandLineArguments>
<_TestingPlatformCommandLineArguments>$(_TestingPlatformCommandLineArguments) --report-xunit-junit-filename %22$(MSBuildProjectName).$(TargetFramework).junit.xml%22</_TestingPlatformCommandLineArguments>
</PropertyGroup>
<CreateProperty Value="$(TestingPlatformCommandLineArguments) $(_TestingPlatformCommandLineArguments)" Condition=" '$(_TestingPlatformCommandLineArguments)' != '' ">
<Output TaskParameter="Value" PropertyName="TestingPlatformCommandLineArguments" />
</CreateProperty>
</Target>
<UsingTask TaskName="WriteLinesToFileWithRetry" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<File ParameterType="System.String" Required="true" />
Expand Down Expand Up @@ -48,19 +59,6 @@
]]></Code>
</Task>
</UsingTask>
<Target Name="GenerateCoverageReports" AfterTargets="GenerateCoverageResultAfterTest" Condition=" '$(CollectCoverage)' == 'true' ">
<ReportGenerator ReportFiles="@(CoverletReport)" ReportTypes="$(ReportGeneratorReportTypes)" Tag="$(Version)" TargetDirectory="$(CoverletReportsPath)" Title="$(AssemblyName)" VerbosityLevel="Warning" />
<PropertyGroup Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' AND Exists('$(ReportGeneratorMarkdownSummary)') ">
<_ReportSummaryContent>&lt;details&gt;&lt;summary&gt;:chart_with_upwards_trend: &lt;b&gt;$(AssemblyName) Code Coverage report&lt;/b&gt; %28$(TargetFramework)%29&lt;/summary&gt;</_ReportSummaryContent>
<_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine)</_ReportSummaryContent>
<_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine)</_ReportSummaryContent>
<_ReportSummaryContent>$(_ReportSummaryContent)$([System.IO.File]::ReadAllText('$(ReportGeneratorMarkdownSummary)'))</_ReportSummaryContent>
<_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine)</_ReportSummaryContent>
<_ReportSummaryContent>$(_ReportSummaryContent)$([System.Environment]::NewLine)</_ReportSummaryContent>
<_ReportSummaryContent>$(_ReportSummaryContent)&lt;/details&gt;</_ReportSummaryContent>
</PropertyGroup>
<WriteLinesToFileWithRetry Condition=" '$(ReportGeneratorOutputMarkdown)' == 'true' AND Exists('$(ReportGeneratorMarkdownSummary)') " ContinueOnError="WarnAndContinue" File="$(GITHUB_STEP_SUMMARY)" Lines="$(_ReportSummaryContent)" />
</Target>
<Target Name="SetNuGetPackageOutputs" AfterTargets="Pack" Condition=" '$(GITHUB_OUTPUT)' != '' ">
<PropertyGroup>
<_PackageNamesPath>$(ArtifactsPath)\package-names.txt</_PackageNamesPath>
Expand Down
7 changes: 2 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
<ItemGroup>
<PackageVersion Include="Autofac.Extensions.DependencyInjection" Version="11.0.2" />
<PackageVersion Include="BenchmarkDotNet" Version="0.15.8" />
<PackageVersion Include="coverlet.msbuild" Version="6.0.4" />
<PackageVersion Include="GitHubActionsTestLogger" Version="3.0.5" />
<PackageVersion Include="IdentityServer4" Version="3.1.4" />
<PackageVersion Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
<PackageVersion Include="JunitXml.TestLogger" Version="8.0.0" />
<PackageVersion Include="MartinCostello.Logging.XUnit.v3" Version="0.7.1" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.31" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.31" />
Expand All @@ -21,17 +19,16 @@
<PackageVersion Include="Microsoft.OpenApi.YamlReader" Version="2.7.6" />
<PackageVersion Include="Microsoft.Playwright" Version="1.63.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.10.1" />
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="18.11.2" />
<PackageVersion Include="MSBuild.ProjectCreation" Version="20.0.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.4" />
<PackageVersion Include="NJsonSchema" Version="11.6.1" />
<PackageVersion Include="NSubstitute" Version="6.2.0" />
<PackageVersion Include="NSwag.CodeGeneration.CSharp" Version="14.7.1" />
<PackageVersion Include="NSwag.MSBuild" Version="14.7.1" />
<PackageVersion Include="ReportGenerator" Version="5.5.11" />
<PackageVersion Include="Verify.XunitV3" Version="33.3.1" />
<PackageVersion Include="xunit" Version="2.9.3" />
<PackageVersion Include="xunit.runner.visualstudio" Version="4.0.0" />
<PackageVersion Include="xunit.v3.mtp-off" Version="4.0.1" />
<PackageVersion Include="xunit.v3.extensibility.core" Version="4.0.1" />
<PackageVersion Include="xunit.v3.mtp-v2" Version="4.0.1" />
</ItemGroup>
</Project>
73 changes: 66 additions & 7 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,80 @@ param(
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"

$solutionPath = $PSScriptRoot
$coverageOutputPath = Join-Path $solutionPath "artifacts" "coverage"

if ([string]::IsNullOrEmpty(${env:GITHUB_ACTIONS})) {
dotnet tool restore
if ($LASTEXITCODE -ne 0) {
throw "dotnet tool restore failed with exit code $LASTEXITCODE"
}
}

dotnet pack --configuration $Configuration

if ($LASTEXITCODE -ne 0) {
throw "dotnet pack failed with exit code $LASTEXITCODE"
}

$additionalArgs = @()
dotnet test --configuration $Configuration

if (![string]::IsNullOrEmpty(${env:GITHUB_SHA})) {
$additionalArgs += "--logger:GitHubActions;report-warnings=false;summary-include-passed=false"
$additionalArgs += "--logger:junit;LogFilePath=junit.xml"
if ($LASTEXITCODE -ne 0) {
throw "dotnet test failed with exit code $LASTEXITCODE"
}

dotnet test --configuration $Configuration $additionalArgs
$projectCoverageDirectories = Get-ChildItem -Path $coverageOutputPath -Directory -ErrorAction SilentlyContinue

if ($LASTEXITCODE -ne 0) {
throw "dotnet test failed with exit code $LASTEXITCODE"
foreach ($projectCoverageDirectory in $projectCoverageDirectories) {
$projectName = $projectCoverageDirectory.Name
$projectCoveragePath = $projectCoverageDirectory.FullName

$coverageReports = @(
Get-ChildItem -Path $projectCoveragePath -File -Filter "coverage.*.xml" -ErrorAction SilentlyContinue |
Sort-Object -Property Name |
Select-Object -ExpandProperty FullName
)

if ($coverageReports.Count -eq 0) {
continue
}

$reportTypes = @("HTML")

if (-Not [string]::IsNullOrEmpty(${env:GITHUB_STEP_SUMMARY})) {
$reportTypes += "MarkdownSummaryGitHub"
}

$reportGeneratorArgs = @(
"-reports:$($coverageReports -join ';')"
"-targetdir:$projectCoveragePath"
"-reporttypes:$($reportTypes -join ';')"
"-title:$projectName"
"-verbosity:Warning"
)

dotnet tool run reportgenerator @reportGeneratorArgs

if ($LASTEXITCODE -ne 0) {
throw "reportgenerator failed with exit code $LASTEXITCODE"
}

$coverageGitHubSummary = Join-Path $projectCoveragePath "SummaryGithub.md"

if (-Not [string]::IsNullOrEmpty(${env:GITHUB_STEP_SUMMARY}) -and (Test-Path -LiteralPath $coverageGitHubSummary)) {
$summaryContent = @(
"<details><summary>:chart_with_upwards_trend: <b>$projectName Code Coverage report</b></summary>"
""
(Get-Content -LiteralPath $coverageGitHubSummary -Raw)
""
"</details>"
) -join [System.Environment]::NewLine

try {
Add-Content -LiteralPath ${env:GITHUB_STEP_SUMMARY} -Value $summaryContent
}
catch {
Write-Warning "Failed to write GitHub step summary for ${projectName}: $_"
}
}
}
3 changes: 3 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"version": "10.0.401",
"allowPrerelease": false,
"paths": [ ".dotnet", "$host$" ]
},
"test": {
"runner": "Microsoft.Testing.Platform"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit.v3.mtp-off" />
<PackageReference Include="xunit.v3.mtp-v2" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>$(DefaultTargetFrameworks)</TargetFrameworks>
</PropertyGroup>

Expand All @@ -14,8 +15,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit.v3.mtp-v2" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit.v3.mtp-off" />
<PackageReference Include="xunit.v3.mtp-v2" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<PackageReference Include="NJsonSchema" />
<PackageReference Include="Verify.XunitV3" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit.v3.mtp-off" />
<PackageReference Include="xunit.v3.mtp-v2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit.v3.mtp-off" />
<PackageReference Include="xunit.v3.mtp-v2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PackageReference Include="NSubstitute" />
<PackageReference Include="Verify.XunitV3" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit.v3.mtp-off" />
<PackageReference Include="xunit.v3.mtp-v2" />
</ItemGroup>

</Project>
24 changes: 24 additions & 0 deletions tests.runsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<CodeCoverage>
<Attributes>
<Exclude>
<Attribute>^System\.CodeDom\.Compiler\.GeneratedCodeAttribute$</Attribute>
<Attribute>^System\.Diagnostics\.CodeAnalysis\.ExcludeFromCodeCoverageAttribute$</Attribute>
<Attribute>^System\.Diagnostics\.DebuggerNonUserCodeAttribute$</Attribute>
</Exclude>
</Attributes>
<ModulePaths>
<Include>
<ModulePath>.*[\\/]Swashbuckle\.AspNetCore\.[^\\/]*\.dll$</ModulePath>
</Include>
<Exclude>
<ModulePath>.*\\obj\\.*</ModulePath>
<ModulePath>.*\/obj\/.*</ModulePath>
<ModulePath>.*\.Test\.dll$</ModulePath>
<ModulePath>.*\.IntegrationTests\.dll$</ModulePath>
<ModulePath>.*\.TestSupport\.dll$</ModulePath>
</Exclude>
</ModulePaths>
</CodeCoverage>
</Configuration>
Loading