Create Custom Exception with one parameter
3.1 Create property
3.2 Create Constructor with one Parameter.
Constructor calls base with Resource String.
Constructor assigns parameter value to property
Create .NET 7 MSTestTest Project
Create Test:
Create the Custom Exception with a valid value.
Assert the property (= parameter value) and the message (= Resource String).
Check that the test passes.
Open terminal on solution folder
run stryker (3.6.1) using "dotnet-stryker"
Stryker terminal output:
Identifying projects to mutate in [..]\StrykerError\StrykerError.sln. This can take a while.
Found 1 source projects
Found 1 test projects
The project [..]\StrykerError\StrykerError\StrykerError.csproj will be mutated.
Analysis complete.
Total number of tests found: 1.
Initial testrun started.
1 mutants created
Capture mutant coverage using 'CoverageBasedTest' mode.
1 mutants got status NoCoverage. Reason: Not covered by any test.
1 total mutants are skipped for the above mentioned reasons
0 total mutants will be tested
It looks like all non-ignored mutants are not covered by a test. Go add some tests!
Killed: 0
Survived: 0
Timeout: 0
Your html report has been generated at:
[..]mutation-report.html
You can open it in your browser of choice.
Time Elapsed 00:00:29.8427304
The final mutation score is 0.00 %
Stryker correctly adds a Block removal mutation for the Property assignment in the constructor.
Stryker assumes that no tests is covering the mutation.
Code:
namespace StrykerError;
public class NameException : Exception
{
public NameException(string name)
: base(Properties.Resources.MyHelloResourceString) // fails
//: base("Hello") // works
{
Name = name;
}
public string Name { get; }
}
Test:
namespace StrykerError.Tests;
[TestClass]
public class NameExceptionTest
{
[TestMethod]
public void Constructor()
{
var name = "Stryker";
var result = new NameException(name);
Assert.AreEqual(result.Name, "Stryker");
Assert.AreEqual(result.Message, "Hello");
}
}
Stryker terminal output:
Stryker correctly adds a Block removal mutation for the Property assignment in the constructor. Stryker assumes that no tests is covering the mutation.
Code:
Test:
Stryker Testresult: