Skip to content

Commit 8affebc

Browse files
authored
Introduce mutation testing (App-vNext#1031)
1 parent 32cf92f commit 8affebc

File tree

9 files changed

+78
-6
lines changed

9 files changed

+78
-6
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ jobs:
5252
files: ./src/Polly.Specs/coverage-reports/Cobertura.xml,./src/Polly.Core.Tests/coverage-reports/Cobertura.xml
5353
flags: ${{ matrix.os_name }}
5454

55+
- name: Upload Mutation Report
56+
uses: actions/upload-artifact@v3
57+
with:
58+
name: mutation-report-${{ matrix.os_name }}
59+
path: StrykerOutput
60+
5561
- name: Publish NuGet packages
5662
uses: actions/upload-artifact@v3
5763
with:

build.cake

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var configuration = Argument<string>("configuration", "Release");
1010
//////////////////////////////////////////////////////////////////////
1111

1212
#Tool "xunit.runner.console&version=2.4.2"
13+
#Tool "dotnet-stryker&version=3.6.1"
1314

1415
//////////////////////////////////////////////////////////////////////
1516
// EXTERNAL NUGET LIBRARIES
@@ -46,6 +47,10 @@ string nugetVersion;
4647
string assemblyVersion;
4748
string assemblySemver;
4849

50+
// Stryker / Mutation Testing
51+
var strykerConfig = File("./eng/stryker-config.json");
52+
var strykerOutput = Directory("StrykerOutput");
53+
4954
///////////////////////////////////////////////////////////////////////////////
5055
// INNER CLASSES
5156
///////////////////////////////////////////////////////////////////////////////
@@ -84,7 +89,8 @@ Task("__Clean")
8489
{
8590
testResultsDir,
8691
nupkgDestDir,
87-
artifactsDir
92+
artifactsDir,
93+
strykerOutput
8894
};
8995

9096
CleanDirectories(cleanDirectories);
@@ -206,6 +212,27 @@ Task("__RunTests")
206212
}
207213
});
208214

215+
Task("__RunMutationTests")
216+
.Does(() =>
217+
{
218+
TestProject(File("./src/Polly/Polly.csproj"), File("./src/Polly.Specs/Polly.Specs.csproj"), "Polly");
219+
TestProject(File("./src/Polly.Core/Polly.Core.csproj"), File("./src/Polly.Core.Tests/Polly.Core.Tests.csproj"), "Polly.Core");
220+
221+
void TestProject(FilePath proj, FilePath testProj, string project)
222+
{
223+
var strykerPath = Context.Tools.Resolve("Stryker.CLI.dll");
224+
var mutationScore = XmlPeek(proj, "/Project/PropertyGroup/MutationScore/text()", new XmlPeekSettings { SuppressWarning = true });
225+
var score = int.Parse(mutationScore);
226+
227+
Information($"Running mutation tests for '{proj}'. Test Project: '{testProj}'");
228+
var result = StartProcess("dotnet", $"{strykerPath} --project {project} --test-project {testProj} --break-at {score} --config-file {strykerConfig} --output {strykerOutput}/{project}");
229+
if (result != 0)
230+
{
231+
throw new InvalidOperationException($"The mutation testing of '{project}' project failed.");
232+
}
233+
}
234+
});
235+
209236
Task("__CreateSignedNuGetPackages")
210237
.Does(() =>
211238
{
@@ -240,6 +267,7 @@ Task("Build")
240267
.IsDependentOn("__UpdateAssemblyVersionInformation")
241268
.IsDependentOn("__BuildSolutions")
242269
.IsDependentOn("__RunTests")
270+
.IsDependentOn("__RunMutationTests")
243271
.IsDependentOn("__CreateSignedNuGetPackages");
244272

245273
///////////////////////////////////////////////////////////////////////////////

eng/Common.targets

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<SignAssembly>true</SignAssembly>
55
<LangVersion>latest</LangVersion>
66
<ImplicitUsings>enable</ImplicitUsings>
7-
<RootDir>$(MSBuildThisFileDirectory)..\</RootDir>
87
<ContinuousIntegrationBuild Condition=" '$(CI)' != '' ">true</ContinuousIntegrationBuild>
98
</PropertyGroup>
109

eng/stryker-config.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"stryker-config": {
3+
"reporters": [
4+
"json",
5+
"html",
6+
"markdown"
7+
],
8+
"ignore-methods": [
9+
"*Exception.ctor",
10+
"AddError",
11+
"ConfigureAwait",
12+
"Dispose",
13+
"LogError",
14+
"LogInformation"
15+
],
16+
"ignore-mutations": [
17+
"block",
18+
"statement"
19+
],
20+
"target-framework": "net7.0",
21+
"thresholds": {
22+
"high": 100,
23+
"low": 100
24+
}
25+
}
26+
}

src/Directory.Build.props

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<Project>
2-
<Import Project="../eng/Common.targets" />
3-
42
<ItemGroup>
53
<Using Include="System.Collections" />
64
<Using Include="System.Collections.Concurrent" />

src/Directory.Build.targets

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<Project>
2-
<Import Project="$(RootDir)eng/Test.targets" Condition="$(ProjectType) == 'Test'" />
3-
<Import Project="$(RootDir)eng/Library.targets" Condition="$(ProjectType) == 'Library'" />
2+
<Import Project="$(MsBuildThisFileDirectory)../eng/Common.targets" />
3+
<Import Project="$(MsBuildThisFileDirectory)../eng/Test.targets" Condition="$(ProjectType) == 'Test'" />
4+
<Import Project="$(MsBuildThisFileDirectory)../eng/Library.targets" Condition="$(ProjectType) == 'Library'" />
45
</Project>

src/Polly.Core.Tests/DummyTest.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Xunit;
2+
3+
namespace Polly.Core.Tests;
4+
5+
public class DummyTest
6+
{
7+
[Fact]
8+
public void Success()
9+
{
10+
Assert.True(true);
11+
}
12+
}

src/Polly.Core/Polly.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<ProjectType>Library</ProjectType>
1010
<UseDefaultAnalyzers>true</UseDefaultAnalyzers>
1111
<SkipPollyUsings>true</SkipPollyUsings>
12+
<MutationScore>100</MutationScore>
1213
</PropertyGroup>
1314

1415
<ItemGroup>

src/Polly/Polly.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<TargetFrameworks>netstandard1.1;netstandard2.0;net461;net472</TargetFrameworks>
55
<AssemblyTitle>Polly</AssemblyTitle>
66
<ProjectType>Library</ProjectType>
7+
<MutationScore>70</MutationScore>
78
</PropertyGroup>
89

910
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.1' ">

0 commit comments

Comments
 (0)