Skip to content

Commit

Permalink
Merge pull request #172 from hamed-shirbandi/faet-165-mutation-testin…
Browse files Browse the repository at this point in the history
…g-using-strykernet

Add Mutation Testing using Stryker
  • Loading branch information
hamed-shirbandi authored Oct 8, 2023
2 parents fce6c81 + d30d1fc commit 54dec54
Show file tree
Hide file tree
Showing 14 changed files with 469 additions and 16 deletions.
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-stryker": {
"version": "3.10.0",
"commands": [
"dotnet-stryker"
]
}
}
}
26 changes: 15 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@ name: build

on:
pull_request:
branches: [ "master" ]
branches: ["master"]
push:
branches: [ "master" ]

branches: ["master"]

jobs:
build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
- name: Run nuke build
run: ./build.ps1
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.x
- name: Build
run: ./build.ps1 Compile
- name: Unit Test
run: ./build.ps1 RunUnitTests --skip Compile
- name: Mutation Test
run: ./build.ps1 RunMutationTests --skip RunUnitTests
env:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -673,3 +673,4 @@ fabric.properties
ocelot.json
/src/2-Services/Identity/Api/Identity.Api/keys
/src/6-Docker/mssqldata/Entropy.bin
/.nuke/temp/execution-plan.html
4 changes: 4 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
"Information",
"Preparation",
"Restore",
"RestoreDotNetTool",
"RunMutationTests",
"RunUnitTests"
]
}
Expand All @@ -95,6 +97,8 @@
"Information",
"Preparation",
"Restore",
"RestoreDotNetTool",
"RunMutationTests",
"RunUnitTests"
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Grpc.Core;
using Grpc.Core.Interceptors;
using Microsoft.Extensions.Logging;
using System.Text.Json;

namespace TaskoMask.BuildingBlocks.Web.MVC.Exceptions
{
Expand All @@ -27,7 +28,7 @@ public override async Task<TResponse> UnaryServerHandler<TRequest, TResponse>(
}
catch (Exception exception)
{
_logger.LogError(exception, exception.Message);
_logger.LogError(exception, $"request : {JsonSerializer.Serialize(request)}");

throw new RpcException(new Status(StatusCode.Cancelled, exception.Message));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

<ItemGroup>
<ProjectReference Include="..\Boards.Write.Tests.Base\Boards.Write.Tests.Base.csproj" />
<ProjectReference Include="..\..\Api\Boards.Write.Api\Boards.Write.Api.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"stryker-config": {
"solution": "../../../../../TaskoMask.sln",
"project": "Boards.Write.Api.csproj",
"thresholds": {
"high": 90,
"low": 60,
"break": 30
},
"mutate": [
"**/*UseCase.cs"
],
"reporters": [
"html",
"progress"
],
"project-info": {
"module": "TaskoMask",
"name": "github.com/hamed-shirbandi/taskomask",
"version": "master"
}
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"stryker-config": {
"solution": "../../../../../TaskoMask.sln",
"project": "Identity.Api.csproj",
"thresholds": {
"high": 90,
"low": 60,
"break": 30
},
"mutate": [
"**/*UseCase.cs"
],
"reporters": [
"html",
"progress"
],
"project-info": {
"module": "TaskoMask",
"name": "github.com/hamed-shirbandi/taskomask",
"version": "master"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<ItemGroup>
<ProjectReference Include="..\Owners.Write.Tests.Base\Owners.Write.Tests.Base.csproj" />
<ProjectReference Include="..\..\Api\Owners.Write.Api\Owners.Write.Api.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"stryker-config": {
"solution": "../../../../../TaskoMask.sln",
"project": "Owners.Write.Api.csproj",
"thresholds": {
"high": 90,
"low": 60,
"break": 30
},
"mutate": [
"**/*UseCase.cs"
],
"reporters": [
"html",
"progress"
],
"project-info": {
"module": "TaskoMask",
"name": "github.com/hamed-shirbandi/taskomask",
"version": "master"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

<ItemGroup>
<ProjectReference Include="..\Tasks.Write.Tests.Base\Tasks.Write.Tests.Base.csproj" />
<ProjectReference Include="..\..\Api\Tasks.Write.Api\Tasks.Write.Api.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"stryker-config": {
"solution": "../../../../../TaskoMask.sln",
"project": "Tasks.Write.Api.csproj",
"thresholds": {
"high": 90,
"low": 60,
"break": 30
},
"mutate": [
"**/*UseCase.cs"
],
"reporters": [
"html",
"progress"
],
"project-info": {
"module": "TaskoMask",
"name": "github.com/hamed-shirbandi/taskomask",
"version": "master"
}
}
}
29 changes: 25 additions & 4 deletions src/6-Build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
using static Nuke.Common.Tools.NuGet.NuGetTasks;
using static Nuke.Common.Tools.NuGet.NuGetPackSettingsExtensions;
using Nuke.Common.IO;
using Nuke.Common.Utilities.Collections;

class Build : NukeBuild
{
public static int Main() => Execute<Build>(x => x.RunUnitTests);
public static int Main() => Execute<Build>(x => x.RunMutationTests);

[Parameter]
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
Expand All @@ -27,10 +26,9 @@ class Build : NukeBuild
readonly Solution Solution;

[Parameter]
AbsolutePath TestResultDirectory = RootDirectory + "/Artifacts/Test-Results/";
AbsolutePath TestResultDirectory = RootDirectory + "/.nuke/Artifacts/Test-Results/";

Target Information => _ => _
.Before(Preparation)
.Executes(() =>
{
Log.Information($"Solution path : {Solution}");
Expand All @@ -46,6 +44,12 @@ class Build : NukeBuild
TestResultDirectory.CreateOrCleanDirectory();
});

Target RestoreDotNetTool => _ => _
.Executes(() =>
{
DotNet(arguments: "tool restore");
});

Target Clean => _ => _
.DependsOn(Preparation)
.Executes(() =>
Expand Down Expand Up @@ -91,4 +95,21 @@ class Build : NukeBuild
.AddLoggers($"trx;LogFileName={z.Name}.trx")
.SetCoverletOutput(TestResultDirectory + $"{z.Name}.xml")));
});

Target RunMutationTests => _ => _
.DependsOn(RunUnitTests,RestoreDotNetTool)
.Executes(() =>
{
//It uses dashboard report for CI
string report = "--reporter dashboard";

//It uses reports specified in reports section in stryker-config.json
if (IsLocalBuild)
report = "";

var testProjects = Solution.AllProjects.Where(s => s.Name.EndsWith(".Tests.Unit"));

foreach (var testProject in testProjects)
DotNet(workingDirectory: testProject.Directory, arguments: $"stryker {report}");
});
}

0 comments on commit 54dec54

Please sign in to comment.