Skip to content

Use dotnet test reporter to see coverage after build #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 25, 2025
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
30 changes: 29 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,32 @@ jobs:
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
id: test
run: dotnet test --no-build --logger "trx;LogFileName=TestResults.trx" --collect "XPlat Code Coverage"
continue-on-error: true
- name: Find .trx
id: trx
run: |
$path = (ls -Recurse -Filter *.trx | select -First 1).FullName
"path=$path" >> $env:GITHUB_OUTPUT
- name: Find coverage*.xml
id: coverage
run: |
$path = (ls -Recurse -Filter coverage*.xml | select -First 1).FullName
"path=$path" >> $env:GITHUB_OUTPUT
- name: Test report
if: ${{ !cancelled() }}
uses: bibipkins/[email protected]
env:
TRX_PATH: ${{ steps.trx.outputs.path }}
COVERAGE_PATH: ${{ steps.coverage.outputs.path }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-title: Test results
results-path: ${{ env.TRX_PATH }}
coverage-type: cobertura
coverage-path: ${{ env.COVERAGE_PATH }}
coverage-threshold: 80
- name: Fail if any step has failed
if: ${{ failure() }}
run: exit 1
4 changes: 2 additions & 2 deletions DisplayDetective.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</Target>

<Target Name="CleanBinObj" AfterTargets="Clean">
<Message Importance="high" Text="Deleting bin/ and obj/ directories" />
<RemoveDir Directories="obj;bin" />
<Message Importance="high" Text="Deleting bin/, obj/ and TestResults/ directories" />
<RemoveDir Directories="obj;bin;TestResults" />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public class DisplayDetectiveServiceTests
{
private static IEnumerable<TheoryDataRow<string>> GetConfigFiles(string subDirectory)
{
var directory = Path.Combine("testsettings", subDirectory);
var directory = Path.Combine("TestSettings", subDirectory);
return Directory.GetFiles(directory, "*.json").Select(f => new TheoryDataRow<string>(f));
}

public static IEnumerable<TheoryDataRow<string>> GetGoodConfigFiles() => GetConfigFiles("good");
public static IEnumerable<TheoryDataRow<string>> GetBadConfigFiles() => GetConfigFiles("bad");

private static IConfiguration GetGoodConfig(string fileName) => new ConfigurationBuilder()
.AddJsonFile(Path.Combine("testsettings", "good", fileName + ".json"))
.AddJsonFile(Path.Combine("TestSettings", "good", fileName + ".json"))
.Build();

private static IConfiguration GoodConfiguration => GetGoodConfig("both-commands-with-args");
Expand All @@ -45,7 +45,7 @@ public void Ctor_InvalidConfig_Fails()
Assert.Throws<InvalidDataException>(() => new DisplayDetectiveService(
Mock.Of<ILogger<DisplayDetectiveService>>(),
new ConfigurationBuilder()
.AddJsonFile(Path.Combine("testsettings", "invalid.json"))
.AddJsonFile(Path.Combine("TestSettings", "invalid.json"))
.Build(),
Mock.Of<IDisplayMonitorService>(),
Mock.Of<ICommandRunnerService>()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<PrunePackageReference>true</PrunePackageReference>
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
</PropertyGroup>

<ItemGroup>
<Content Include="xunit.runner.json" CopyToOutputDirectory="PreserveNewest" />
<Content Include="testsettings\**\*.json" CopyToOutputDirectory="PreserveNewest" />
<Content Include="TestSettings\**\*.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
Expand All @@ -34,14 +31,8 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="xunit.v3" Version="1.1.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2" />
<PackageReference Include="coverlet.collector" Version="6.0.4" />
</ItemGroup>

<Import Project="..\DisplayDetective.Common.targets" />
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ dotnet test
cd DisplayDetective.CommandLineApp
dotnet run -- list
dotnet run -- monitor
dotnet msbuild /t:clean
```

## 🤝 Contributing
Expand Down