Skip to content

Commit

Permalink
Add mutation testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jnyrup committed Apr 22, 2023
1 parent 776e577 commit 75b6775
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
run: ./build.ps1
env:
NuGetApiKey: ${{ secrets.NUGETAPIKEY }}
StrykerApiKey: ${{ secrets.STRYKERAPIKEY }}

- name: Check for 'lcov.info' existence
id: check_files
Expand Down
7 changes: 7 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"Clean",
"CodeCoverage",
"Compile",
"MutationTests",
"Pack",
"Push",
"Restore",
Expand All @@ -93,6 +94,11 @@
"type": "string",
"description": "Path to a solution file that is automatically loaded"
},
"StrykerApiKey": {
"type": "string",
"description": "The key to push to Stryker",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"Target": {
"type": "array",
"description": "List of targets to be invoked. Default is '{default_target}'",
Expand All @@ -104,6 +110,7 @@
"Clean",
"CodeCoverage",
"Compile",
"MutationTests",
"Pack",
"Push",
"Restore",
Expand Down
37 changes: 37 additions & 0 deletions Build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class Build : NukeBuild
[Secret]
readonly string NuGetApiKey;

[Parameter("The key to push to Stryker")]
[Secret]
readonly string StrykerApiKey;

[Solution(GenerateProjects = true)]
readonly Solution Solution;

Expand Down Expand Up @@ -261,6 +265,38 @@ void ReportTestOutcome(params string[] globFilters)
Information($"Code coverage report: \x1b]8;;file://{link.Replace('\\', '/')}\x1b\\{link}\x1b]8;;\x1b\\");
});

Target MutationTests => _ => _
.OnlyWhenDynamic(() => EnvironmentInfo.IsWin && (RunAllTargets || HasSourceChanges))
.Executes(() =>
{
var strykerPath = ToolPathResolver.GetPackageExecutable("dotnet-stryker", "Stryker.CLI.dll", framework: "net6.0");
string arguments =
$"{strykerPath}" +
$" --project {Solution.Core.FluentAssertions}" +
$" --test-project {Solution.Specs.FluentAssertions_Specs}" +
$" --test-project {Solution.Specs.FluentAssertions_Equivalency_Specs}" +
$" --config-file {BuildProjectDirectory / "stryker-config.json"}";
if (IsPullRequest)
{
arguments +=
" --reporter dashboard" +
$" --dashboard-api-key {StrykerApiKey}";
//$" --version {GitHubActions.Sha}"+
//$" --with-baseline:{GitHubActions.Sha}";
}
else
{
arguments +=
" --reporter html" +
" --reporter progress" +
$" --output {Solution.Directory / "StrykerOutput"}";
}
DotNet(arguments,
workingDirectory: Solution.Core.FluentAssertions.Directory);
});

Target TestFrameworks => _ => _
.DependsOn(Compile)
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
Expand Down Expand Up @@ -310,6 +346,7 @@ from framework in supportedFrameworks
.DependsOn(TestFrameworks)
.DependsOn(UnitTests)
.DependsOn(CodeCoverage)
.DependsOn(MutationTests)
.DependsOn(CalculateNugetVersion)
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
.Executes(() =>
Expand Down
1 change: 1 addition & 0 deletions Build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<DefineConstants>OS_MAC</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageDownload Include="dotnet-stryker" Version="[3.7.1]" />
<PackageDownload Include="GitVersion.Tool" Version="[5.12.0]" />
<PackageDownload Include="NSpec" Version="[3.1.0]" />
<PackageDownload Include="ReportGenerator" Version="[5.1.19]" />
Expand Down
21 changes: 21 additions & 0 deletions Build/stryker-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"stryker-config": {
"project-info": {
"name": "github.com/jnyrup/fluentassertions"
},
"mutation-level": "Basic",
"ignore-methods": [
],
"ignore-mutations": [
"Arithmetic",
"Block",
"Equality",
"Logical"
],
"target-framework": "net6.0",
"thresholds": {
"high": 100,
"low": 100
}
}
}

0 comments on commit 75b6775

Please sign in to comment.