### Install and run Stryker.NET with dotnet tool Source: https://github.com/stryker-mutator/stryker-net/blob/master/README.md Use these commands to install the dotnet-stryker tool globally and run it in your test project folder. The first command installs the tool, the second navigates to the test project directory, and the third executes Stryker to perform mutation testing. ```bash dotnet tool install -g dotnet-stryker cd /my/unit/test/project/folder dotnet stryker ``` -------------------------------- ### Install Stryker globally Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/getting-started.md Installs Stryker as a global dotnet tool using the -g flag. ```bash dotnet tool install -g dotnet-stryker ``` -------------------------------- ### Create tool manifest Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/getting-started.md Creates a dotnet-tools.json file in the project folder for local tool installation. ```bash dotnet new tool-manifest ``` -------------------------------- ### Install Stryker in Azure DevOps with --tool-path Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/stryker-in-pipeline.md Uses DotNetCoreCLI@2 task to install dotnet-stryker as a local tool with --tool-path pointing to $(Agent.BuildDirectory)/tools. ```yaml - task: DotNetCoreCLI@2 displayName: 'Install dotnet-stryker' inputs: command: custom custom: tool arguments: install dotnet-stryker --tool-path $(Agent.BuildDirectory)/tools ``` -------------------------------- ### Stryker configuration file Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/getting-started.md Example stryker-config.json file to store options like reporters, so they don't need to be passed via CLI each run. ```json { "stryker-config": { "reporters": [ "progress", "html" ] } } ``` -------------------------------- ### Install Stryker locally Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/getting-started.md Installs Stryker as a local tool without the -g flag, after creating the tool manifest. ```bash dotnet tool install dotnet-stryker ``` -------------------------------- ### Baseline fallback-version example: since-target and current-branch Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md Shows the configuration values for since-target and current-branch used in the fallback-version examples. ```json "since-target": 'development', "current-branch" 'feat-2' ``` -------------------------------- ### Copy VS Code configuration templates Source: https://github.com/stryker-mutator/stryker-net/blob/master/CONTRIBUTING.md Copy the example configuration files to create local launch.json and tasks.json for debugging in Visual Studio Code. On Windows, copy the contents manually. ```bash cp .vscode/launch.json.example .vscode/launch.json cp .vscode/tasks.json.example .vscode/tasks.json ``` -------------------------------- ### Stryker comments example in C# Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/ignore-mutations.md Example showing how to use Stryker comments to control mutation testing at the source level. It demonstrates 'disable all', 'restore all', and 'disable once' with specific mutator lists. ```csharp var i = 0; var y = 10; // Stryker disable all : for explanatory reasons i++; // won't be mutated y++; // won't be mutated // Stryker restore all i--; // will be mutated i++; // will be mutated // Stryker disable once Arithmetic y++; // will be mutated // Stryker disable once Arithmetic,Update i--; // won't be mutated ``` -------------------------------- ### Enable dashboard baseline in Azure DevOps with --with-baseline Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/stryker-in-pipeline.md Starts baseline run comparing against the target branch and uses dashboard API key and source branch version. ```bash dotnet stryker --with-baseline:$(System.PullRequest.TargetBranch) --dashboard-api-key $(Stryker.Dashboard.Api.Key) --version $(System.PullRequest.SourceBranch) ``` -------------------------------- ### Example stryker-config.yaml file Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md YAML configuration file for Stryker.NET. Place it in the unit test project folder and name it stryker-config.yaml. The configuration section must be called 'stryker-config'. ```yaml stryker-config: solution: '../SolutionFile.sln' project: 'ExampleProject.csproj' ``` -------------------------------- ### Example stryker-config.json file Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md JSON configuration file for Stryker.NET. Place it in the unit test project folder and name it stryker-config.json. The configuration section must be called 'stryker-config'. ```json { "stryker-config": { "solution": "../SolutionFile.sln", "project": "ExampleProject.csproj" } } ``` -------------------------------- ### Baseline fallback-version example: baseline exists for both feat-2 and development Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md When a baseline exists for the current branch, it is used and the new baseline is saved for feat-2. ```json baseline exists for branch feat-2: true baseline exists for branch development: true baseline used: feat-2 new baseline saved to: feat-2 ``` -------------------------------- ### Ignore method signatures with wildcards in stryker-config Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md Configure `ignore-methods` in the `stryker-config` JSON to skip specified method signatures from mutation. Supports wildcards and `.ctor` suffix for constructors. Example shows ignoring methods ending with `Log`, starting with `Write` in `Console`, and all exception constructors. ```json "stryker-config": { "ignore-methods": [ "*Log", // Ignores all methods ending with Log "Console.Write*", // Ignores all methods starting with Write in the class Console "*Exception.ctor" // Ignores all exception constructors ] } ``` -------------------------------- ### Run locally installed dotnet-stryker in Azure DevOps Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/stryker-in-pipeline.md Runs the tool installed in the common agent folder using a PowerShell inline script. ```yaml - task: Powershell@2 displayName: 'Run dotnet-stryker' inputs: workingDirectory: targetType: 'inline' pwsh: true script: $(Agent.BuildDirectory)/tools/dotnet-stryker ``` -------------------------------- ### Baseline fallback-version example: no baseline exists for feat-2 or development Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md When no baseline exists for the current branch or the fallback version, a complete testrun is performed and saved as the new baseline for feat-2. ```json baseline exists for branch feat-2: false baseline exists for branch development: false baseline used: null (complete instead of partial testrun) new baseline saved to: feat-2 ``` -------------------------------- ### Mutant schemata if statement example Source: https://github.com/stryker-mutator/stryker-net/wiki/2.-Research Shows the mutant schemata technique where all mutations are placed inside if statements controlled by an environment variable. The mutated code is executed when the variable matches, otherwise the original code runs. ```csharp if(Environment.GetEnvironmentVariable("ActiveMutation") == "1") { i--; // mutated code } else { i++; // original code } ``` -------------------------------- ### NUnit test execution run sequence Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/technical-reference/testing-framework.md Shows the sequence of events during NUnit test execution with TestCaseSource, including when the data source is enumerated and when test cases start and end. ```text NUnit runner calls the TestCaseSource and gets every test case. TestSession start event ... NUnit discovers test NUnit enumerates data source (for tests) ... TestCase start event NUnit run test with first set of data NUnit run test with second set of data ... NUnit reports test result TestCase end event ... NUnit reports last test result TestCase end event TestCase start event ... ``` -------------------------------- ### Baseline fallback-version example: no baseline for feat-2, baseline exists for development Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md When no baseline exists for the current branch but one exists for the fallback version, the fallback baseline is used and the new baseline is saved for feat-2. ```json baseline exists for branch feat-2: false baseline exists for branch development: true baseline used: development new baseline saved to: feat-2 ``` -------------------------------- ### C# example of ignored method mutation Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md Shows a C# code snippet where `ConfigureAwait(true)` is skipped because it matches the ignored method signature, while `ConfigureAwait(t)` with a variable is not detected and thus not skipped. ```csharp // This mutation will be skipped ConfigureAwait(true); // This mutation won't because we cannot currently detect this var t = true; ConfigureAwait(t); ``` -------------------------------- ### Statement and block removal mutations Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/mutations.md Mutates statements and blocks by removing them. For example, `void Function() { Age++; }` becomes an empty block, `return;` is removed, and `MyMethodCall();` is removed. ```csharp `void Function() { Age++; }` ``` ```csharp `void Function() {} (block emptied)` ``` ```csharp `int Function() { Age++; return Age; }` ``` ```csharp `void Function() { return default; } (block emptied)` ``` ```csharp `return;` ``` ```csharp `removed` ``` ```csharp `return value;` ``` ```csharp `break;` ``` ```csharp `continue;` ``` ```csharp `goto;` ``` ```csharp `throw;` ``` ```csharp `throw exception;` ``` ```csharp `yield return value;` ``` ```csharp `yield break;` ``` ```csharp `MyMethodCall();` ``` -------------------------------- ### C# example of attempted mutation of constant value Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/technical-reference/mutant-schemata.md Shows the attempted mutation of the constant expression in the enum, which would not compile because MutantControl.IsActive(0) is not a constant value. This illustrates why constant values are skipped. ```cs public enum Numbers { One = 1, Two = (MutantControl.IsActive(0) ? (One - 1) : (One + 1)) } ``` -------------------------------- ### Stryker disable once within an expression Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/ignore-mutations.md Use the 'once' keyword within an expression to ignore mutations only for the next syntax construct. In this example, only mutations impacting SomeMethod(x*5) are ignored. ```csharp x = x + // Stryker disable once Arithmetic SomeMethod(x*5) * SomeOtherMethod(x/2); ``` -------------------------------- ### C# example of constant value mutation limitation Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/technical-reference/mutant-schemata.md Shows an enum with a constant expression that cannot be mutated because MutantControl.IsActive(0) is not a constant value. Stryker.NET skips mutating constant values for this reason. ```cs public enum Numbers { One = 1, Two = (One + 1) } ``` -------------------------------- ### Assignment operator mutations Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/mutations.md Mutates compound assignment operators to their counterparts. For example, `+=` becomes `-=`, `*=` becomes `/=`, and `??=` becomes `=`. Note that `&=` and `|=` have two possible mutations each. ```csharp `+=` ``` ```csharp `-=` ``` ```csharp `*=` ``` ```csharp `/=` ``` ```csharp `%=` ``` ```csharp `<<=` ``` ```csharp `>>=` ``` ```csharp `&=` ``` ```csharp `^=` ``` ```csharp `|=` ``` ```csharp `??=` ``` -------------------------------- ### Constant value mutation example: enum Source: https://github.com/stryker-mutator/stryker-net/wiki/3.-Mutant-schemata Demonstrates a constant value that cannot be mutated because the generated code would not compile. The original enum uses a constant expression, but the mutated version uses a non-constant method call. ```cs public enum Numbers { One = 1, Two = (One + 1) } ``` ```cs public enum Numbers { One = 1, Two = (MutantControl.IsActive(0) ? (One - 1) : (One + 1)) } ``` -------------------------------- ### Scope error example: variable declaration inside if Source: https://github.com/stryker-mutator/stryker-net/wiki/3.-Mutant-schemata Illustrates a mutation that changes variable scope, causing a compile error because 'i' is not accessible after the if statement. The error location is at the return statement, making rollback difficult. ```csharp if (Environment.GetEnvironmentVariable("ActiveMutation") == "1") { int i = 0; // mutated code } else { int i = 99; // original code } return i; ``` -------------------------------- ### Initializer mutations Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/mutations.md Mutates collection and object initializers by emptying their contents. For example, `new int[] { 1, 2 }` becomes `new int[] { }`, and `new SomeClass { Foo = "Bar" }` becomes `new SomeClass { }`. ```csharp `new int[] { 1, 2 };` ``` ```csharp `new int[] { };` ``` ```csharp `int[] numbers = { 1, 2 };` ``` ```csharp `int[] numbers = { };` ``` ```csharp `new List { 1, 2 };` ``` ```csharp `new List { };` ``` ```csharp `new Collection { 1, 2 };` ``` ```csharp `new Collection { };` ``` ```csharp `new Dictionary { { 1, 1 } };` ``` ```csharp `new Dictionary { };` ``` ```csharp `new SomeClass { Foo = "Bar" };` ``` ```csharp `new SomeClass { };` ``` -------------------------------- ### Compile error example: string subtraction mutation Source: https://github.com/stryker-mutator/stryker-net/wiki/3.-Mutant-schemata Shows a mutation that causes a compile error because subtracting strings is invalid. The mutated code is inside an if statement checking the 'ActiveMutation' environment variable, while the original code is in the else branch. ```csharp if (Environment.GetEnvironmentVariable("ActiveMutation") == "1") { return "hello " - "world"; // mutated code } else { return "hello " + "world"; // original code } ``` -------------------------------- ### Run Stryker with --project option Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/operating-modes.md Specify the source project with --project when the test project has multiple project references. Only one source project can be specified at a time. ```bash cd /my-solution-dir/my-test-project-dir dotnet stryker --project ``` -------------------------------- ### Run Stryker from source project with --test-project Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/operating-modes.md Run Stryker from the source project context, passing the test project location with --test-project. ```bash cd /my-solution-dir/my-source-project-dir dotnet stryker --test-project "../my-test-project-dir/tests.csproj" ``` -------------------------------- ### Run Stryker.NET with markdown reporter Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/reporters.md Run Stryker.NET with the markdown reporter to generate a Markdown summary file named mutation-report.md in the StrykerOutput/{date-time}/reports directory. ```bash dotnet stryker --reporter "markdown" ``` -------------------------------- ### Enable HTML reporter Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/reporters.md Activates the HTML reporter, which outputs an HTML file visually displaying the project and all mutations. Recommended for larger projects. ```bash dotnet stryker --reporter "html" ``` -------------------------------- ### Run Stryker Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/getting-started.md Runs Stryker with default configuration, which will find the source project to mutate. ```bash dotnet stryker ``` -------------------------------- ### Run Stryker with explicit solution file Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/operating-modes.md Pass a specific solution file using the --solution option. Stryker prioritizes the solution context over the project context if both solution and project files are in the same folder. ```bash cd /my-solution-dir dotnet stryker --solution "/my-solution-dir/mysolution.sln" ``` -------------------------------- ### Run Stryker from solution directory Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/operating-modes.md Run Stryker from the solution directory. Stryker discovers a single solution file and mutates all projects it can find. ```bash cd /my-solution-dir dotnet stryker ``` -------------------------------- ### Run Stryker with multiple --test-project options Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/operating-modes.md Specify multiple test projects targeting the same source project by repeating the --test-project option. ```bash cd /my-solution-dir/my-source-project-dir dotnet stryker --test-project "../my-test-project-dir/Tests.csproj" --test-project "../my-test-project-dir/MoreTests.csproj" ``` -------------------------------- ### Run Stryker with dots reporter Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/reporters.md Use this reporter on build servers for little/no performance loss while still giving insight. It indicates in a very simple way how many mutants have been tested and their status: "." means killed, "S" means survived, and "T" means timed out. ```bash dotnet stryker --reporter "dots" ``` -------------------------------- ### Run Stryker with cleartext reporter Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/reporters.md Use this reporter for a quick run without leaving files on your system. It displays all files right after the mutation testrun is done. ```bash dotnet stryker --reporter "cleartext" ``` -------------------------------- ### New multi-value reporter option (V1.x) Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/migration-guide.md Shows the new, standard way to pass multiple reporters by repeating the --reporter flag. This replaces the old array syntax. ```shell dotnet stryker --reporter "html" --reporter "progress" ``` -------------------------------- ### Enable SourceLink with DotNet.ReproducibleBuilds Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/reporters.md Adds the DotNet.ReproducibleBuilds package to a .csproj or Directory.Build.props file to enable SourceLink, which allows Stryker to automatically retrieve the project name and version for the dashboard reporter. ```xml ``` -------------------------------- ### Run Stryker with cleartexttree reporter Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/reporters.md Use this reporter for a quick run without leaving files on your system. It displays all mutations right after the mutation testrun is done. It is recommended to turn this reporter off on big projects. ```bash dotnet stryker --reporter "cleartexttree" ``` -------------------------------- ### Run Stryker from test project directory Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/operating-modes.md Run Stryker from the test project folder. Stryker automatically detects the source project based on the project reference. ```bash cd /my-solution-dir/my-test-project-dir dotnet stryker ``` -------------------------------- ### Command line: solution option Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md Specifies the solution file path to help with dependency resolution. Required for .NET Framework projects. ```bash [-s|--solution] "../solution.sln" ``` -------------------------------- ### Command line: project option Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md Specifies the project file name (not path) when the test project has more than one project reference. ```bash [-p|--project] "MyAwesomeProject.csproj" ``` -------------------------------- ### dotnet stryker init command Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md Initializes a new JSON configuration file in the current directory. ```bash dotnet stryker init ``` -------------------------------- ### Run Stryker with trace logging Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/getting-started.md Runs Stryker with trace logging enabled to troubleshoot issues, writing logs to a file. ```bash dotnet stryker --verbosity trace --log-to-file ``` -------------------------------- ### Enable progress reporter Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/reporters.md Activates the progress reporter, which outputs the current status of the mutation test run with a visual progress bar and estimated completion time. Recommended for large projects. ```bash dotnet stryker --reporter "progress" ``` -------------------------------- ### Run Stryker with json reporter Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/reporters.md Use this reporter to output a json file with all mutation testrun info of the last run. The json is also used for the HTML reporter, but using this reporter you could use the file for your own purposes. ```bash dotnet stryker --reporter "json" ``` -------------------------------- ### Command line: configuration option Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md Specifies the build configuration to use when building the project. ```bash --configuration Release ``` -------------------------------- ### Command line: test-projects option Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md Specifies multiple test projects covering one project under test. ```bash [-tp|--test-project] "../Tests/Tests.csproj" -tp "../MoreTests/MoreTests.csproj" ``` -------------------------------- ### dotnet stryker init with custom config file name Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md Creates a configuration file with a custom name using the --config-file option. ```bash dotnet stryker init --config-file "custom.json" ``` -------------------------------- ### Run Stryker with gitlab reporter Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/reporters.md Use this reporter to output a json file named `gitlab_quality.json` with all mutation testrun info of the last run. The json structure follows the GitLab Code Quality report format defined in GitLab Docs. ```bash dotnet stryker --reporter "gitlab" ``` -------------------------------- ### Config file: solution option Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md Specifies the solution file path in the configuration file. ```json "solution": '../solution.sln' ``` -------------------------------- ### Old multi-value reporters option (V0.x) Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/migration-guide.md Shows the old, non-standard way to pass multiple reporters via a single CLI flag, using a JSON-like array string. This is deprecated in V1.x. ```shell dotnet stryker --reporters "['html', 'progress']" ``` -------------------------------- ### Config file: configuration option Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md Specifies the build configuration in the configuration file. ```json "configuration": "Release" ``` -------------------------------- ### Enable dashboard reporter Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/reporters.md Activates the dashboard reporter, which uploads Stryker results as JSON to the Stryker dashboard. Requires configuration of API key, project name, and project version (unless using SourceLink). ```bash dotnet stryker --reporter "dashboard" ``` -------------------------------- ### Config file: project option Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md Specifies the project file name in the configuration file. ```json "project": 'MyAwesomeProject.csproj' ``` -------------------------------- ### JavaScript to set report and theme Source: https://github.com/stryker-mutator/stryker-net/blob/master/src/Stryker.Core/Stryker.Core/Reporters/Html/Files/mutation-report.html This script sets the report data on the app element and updates the theme background color. It listens for theme changes and applies the background color to the body. ```javascript const app = document.querySelector('mutation-test-report-app'); app.report = ##REPORT_JSON##; function updateTheme() { document.body.style.backgroundColor = app.themeBackgroundColor; } app.addEventListener('theme-changed', updateTheme); updateTheme(); ``` -------------------------------- ### Stryker config with Dashboard baseline provider Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/stryker-in-pipeline.md Minimal JSON configuration for setting the baseline provider to Dashboard. ```json { "stryker-config": { "baseline": { "provider": "Dashboard" } } } ``` -------------------------------- ### Config file: test-projects option Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md Specifies multiple test projects in the configuration file. ```json "test-projects": ['../MyProject.UnitTests/MyProject.UnitTests.csproj', '../MyProject.SpecFlow/MyProject.SpecFlow.csproj'] ``` -------------------------------- ### Set mutation score break threshold with --break-at Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/stryker-in-pipeline.md Configure a break threshold to fail the pipeline when the mutation score falls below 80. ```bash dotnet stryker --break-at 80 ``` -------------------------------- ### Check dotnet availability Source: https://github.com/stryker-mutator/stryker-net/blob/master/CONTRIBUTING.md Verify that the dotnet CLI is available in your terminal, especially when troubleshooting 'Command not found' errors in VS Code tasks. ```bash dotnet --version ``` -------------------------------- ### xUnit test execution timeline Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/technical-reference/testing-framework.md Timeline of xUnit test execution in Stryker.NET. Shows discovery, theory enumeration, and per-test-case execution with multiple data sets. Note that each test result includes the total execution time for all data sets, so results should not be summed. ```text TestSession start event xUnit discovers test xUnit discovers theories xUnit enumerates data source (for tests) ... TestCase start event xUnit runs test with first set of data xUnit runs test with second set of data ... xUnit runs test with last set of data xUnit reports first test results TestCase end event xUnit reports second test result ... xUnit reports last test result TestCase start event ... TestSession end event ``` -------------------------------- ### Restore local tools Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/getting-started.md Restores or updates the local Stryker tool for the team using the dotnet-tools.json file. ```bash dotnet tool restore ``` -------------------------------- ### Publish mutation report with PublishMutationReport@1 Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/stryker-in-pipeline.md Adds the mutation report to the build summary in Azure DevOps pipelines. ```yaml - task: PublishMutationReport@1 displayName: 'Publish Mutation Test Report' inputs: reportPattern: '**/mutation-report.html' ``` -------------------------------- ### Command line: mutate option Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md Configures the subset of files to mutate. Can be used multiple times. ```bash [-m|--mutate] "**/*Services.cs" -m "!**/*.Generated.cs" ``` -------------------------------- ### Mutate option to ignore files Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/ignore-mutations.md Ignore whole files from mutation testing using the mutate option with a glob pattern. The JSON configuration and the equivalent command-line flag -m are shown. ```json "stryker-config": { "mutate": ["!**/*.Generated.cs"] } ``` ```bash -m "!**/*.Generated.cs" ``` -------------------------------- ### Command line: test-case-filter option Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md Filter expression to run selective tests using dotnet test --filter syntax. ```bash --test-case-filter "(FullyQualifiedName~UnitTest1&TestCategory=CategoryA)|Priority=1" ``` -------------------------------- ### Run Stryker with debug verbosity Source: https://github.com/stryker-mutator/stryker-net/blob/master/CONTRIBUTING.md Use this command to run Stryker with debug logging when reporting a bug. The output should be included in the issue. ```bash dotnet stryker --verbosity debug ``` -------------------------------- ### dotnet stryker init with mutation level override Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md Overrides default configuration values using regular CLI options, here setting the mutation level to 'advanced'. ```bash dotnet stryker init --mutation-level "advanced" ``` -------------------------------- ### HTML custom element placeholder Source: https://github.com/stryker-mutator/stryker-net/blob/master/src/Stryker.Core/Stryker.Core/Reporters/Html/Files/mutation-report.html The page includes a custom element 'mutation-test-report-app' where the report is rendered. The browser must support custom elements for the report to display. ```html ``` -------------------------------- ### Config file: test-case-filter option Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md Filter expression in the configuration file. ```json "test-case-filter": "(FullyQualifiedName~UnitTest1&TestCategory=CategoryA)|Priority=1" ``` -------------------------------- ### Command line: mutate with span Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md Specifies a span of text to include or exclude using indices. ```bash dotnet stryker -m "MyFolder/MyService.cs{10..100}" ``` -------------------------------- ### Conditional statement solution for scope errors Source: https://github.com/stryker-mutator/stryker-net/wiki/3.-Mutant-schemata Shows how using a conditional (ternary) operator instead of an if statement avoids scope issues. This approach is chosen based on the type of SyntaxNode being mutated. ```csharp int i = Environment.GetEnvironmentVariable("ActiveMutation") == "1" ? 0 : 99; return i; ``` -------------------------------- ### Config file: mutate option Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md Configures the subset of files to mutate in the configuration file. ```json "mutate": ['**/*Services.cs', '!**/*.Generated.cs'] ``` -------------------------------- ### Ignore methods option in stryker-config.json Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/ignore-mutations.md Configure Stryker.NET to ignore specific method calls using glob patterns. This only ignores mutations inside the method calls, not the method declarations. ```json "stryker-config": { "ignore-methods": [ "*Log", // Ignores all methods ending with Log "Console.Write*", // Ignores all methods starting with Write in the class Console "*Exception.ctor" // Ignores all exception constructors ] } ``` -------------------------------- ### Ignore specific LINQ expressions via stryker-config Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/configuration.md Configure `ignore-mutations` in the `stryker-config` JSON to disable specific LINQ mutations, such as `linq.First` and `linq.Sum`. Mutants of ignored types are not tested and appear as `Ignored` in reports. ```json "stryker-config": { "ignore-mutations": [ "linq.First", "linq.Sum" ] } ``` -------------------------------- ### Collection expression mutation: replace empty collection with default Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/mutations.md Mutates `[]` to `[default]` by replacing an empty collection expression with one containing the default value. ```csharp [] ``` ```csharp [default] ``` -------------------------------- ### Collection expression mutation: replace non-empty collection with empty Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/mutations.md Mutates `[1, 2, 3]` to `[]` by replacing a non-empty collection expression with an empty one. ```csharp [1, 2, 3] ``` ```csharp [] ``` -------------------------------- ### Null-coalescing operator mutation: swap operands Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/mutations.md Mutates `a ?? b` to `b ?? a` by swapping the left and right operands of the null-coalescing operator. ```csharp a ?? b ``` ```csharp b ?? a ``` -------------------------------- ### Ignore mutations option in stryker-config.json Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/ignore-mutations.md Configure Stryker.NET to ignore all occurrences of specific mutation types. The option accepts an array of mutation type names, such as "string". ```json "stryker-config": { "ignore-mutations": [ "string" ] } ``` -------------------------------- ### Conditional operator mutation: replace condition with false Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/mutations.md Mutates `x ? a : b` to `false ? a : b` by replacing the condition with the boolean literal `false`. ```csharp x ? a : b ``` ```csharp false ? a : b ``` -------------------------------- ### Conditional operator mutation: replace condition with true Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/mutations.md Mutates `x ? a : b` to `true ? a : b` by replacing the condition with the boolean literal `true`. ```csharp x ? a : b ``` ```csharp true ? a : b ``` -------------------------------- ### Null-coalescing operator mutation: replace with left operand Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/mutations.md Mutates `a ?? b` to `a` by removing the right operand and keeping only the left operand. ```csharp a ?? b ``` ```csharp a ``` -------------------------------- ### Null-coalescing operator mutation: replace with right operand Source: https://github.com/stryker-mutator/stryker-net/blob/master/docs/mutations.md Mutates `a ?? b` to `b` by removing the left operand and keeping only the right operand. ```csharp a ?? b ``` ```csharp b ```