stryker-mutator / stryker-js

Mutation testing for JavaScript and friends
https://stryker-mutator.io
Apache License 2.0
2.58k stars 246 forks source link

[Bug] Using Resource String creates no coverage mutation. #3997

Closed XenoLupus closed 1 year ago

XenoLupus commented 1 year ago
  1. Create .NET 7 Library Project
  2. Create Assembly Resource with one Resource String
  3. 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
  4. Create .NET 7 MSTestTest Project
  5. Create Test: Create the Custom Exception with a valid value. Assert the property (= parameter value) and the message (= Resource String).
  6. Check that the test passes.
  7. Open terminal on solution folder
  8. 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 Testresult: image

XenoLupus commented 1 year ago

Problem exists in .NET Stryker and not JS