Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
run: dotnet test --no-build --verbosity normal --settings coverage.runsettings
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the coverage.runsettings here is the file you have created, this will not find the file as it is looking for this file in this folder. I belive you can use ${{ github.workspace }}/coverage.runsettings. ${{ github.workspace }} should point to the project root folder if I'm not wrong.

4 changes: 4 additions & 0 deletions PatternService/Pattern.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
record Pattern(string Value)
{
public string SomeMethod => Value;
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to trigger failing test coverage report

}
36 changes: 36 additions & 0 deletions PatternServiceTests/PatternServiceTests.csproj
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually in c# .NET you do <proj_name.Tests>. So for our test proj it should be PatternService.Tests.

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

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\PatternService\PatternService.csproj" />
</ItemGroup>

<PropertyGroup>
<CollectCoverage>true</CollectCoverage>
<CoverletOutput>../TestResults/coverage/</CoverletOutput>
<CoverletOutputFormat>cobertura</CoverletOutputFormat>
<Threshold>100</Threshold>
<ThresholdType>method</ThresholdType>
<ThresholdStat>Total</ThresholdStat>
</PropertyGroup>

</Project>
10 changes: 10 additions & 0 deletions PatternServiceTests/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace PatternServiceTests;

public class UnitTest1
{
[Fact]
public void Test1()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make a local method just in this class to make the test fail to prove that the CI-pipeline fails:

    [Fact]
    public void ThisTestWillFail()
    {
        Assert.Equal(5, Add(2, 2));
    }

    private int LocalTestAdd(int x, int y)
    {
        return x + y;
    }

{

}
}
25 changes: 25 additions & 0 deletions coverage.runsettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat Code Coverage">
<Configuration>
<CodeCoverage>
<ModulePaths>
<Include>
<ModulePath>.*PatternService.*</ModulePath>
</Include>
</ModulePaths>
<Exclude>
<Attribute>^System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute$</Attribute>
<Module>.*Test.*</Module>
</Exclude>
<Thresholds>
<Threshold type="method" value="100" />
</Thresholds>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
6 changes: 6 additions & 0 deletions pattern-service.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PatternService", "PatternService\PatternService.csproj", "{7C4D4357-EB66-4CD2-B0AF-9F7A3FC6D1C7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PatternServiceTests", "PatternServiceTests\PatternServiceTests.csproj", "{3026BA50-F64E-42EB-88C9-6246E0A3E121}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{7C4D4357-EB66-4CD2-B0AF-9F7A3FC6D1C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C4D4357-EB66-4CD2-B0AF-9F7A3FC6D1C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C4D4357-EB66-4CD2-B0AF-9F7A3FC6D1C7}.Release|Any CPU.Build.0 = Release|Any CPU
{3026BA50-F64E-42EB-88C9-6246E0A3E121}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3026BA50-F64E-42EB-88C9-6246E0A3E121}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3026BA50-F64E-42EB-88C9-6246E0A3E121}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3026BA50-F64E-42EB-88C9-6246E0A3E121}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down