-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add mutation for conditional (ternary) operator #2581
Comments
This mutator does not seem like it would be hard to add, so if nobody is objecting, I will try to add it. |
ternary expression have a specific type resolution logic when I guess this mutator would benefit for semantic compilation, when/if it is activated. |
@dupdob That is true, replacing the ternary with one of the branches could affect type resolution. |
un killable mutants should not exist here, they would be the sign that the ternary operator is not needed. |
you can have a look at this unit test: granted, this is a different mutations, but it looks to me like it should be give satisfactory results |
@dupdob The mutator you have linked mutates conditional expressions by creating a negation of the expression. |
I think both mutations are equivalent: each survives if the developer failed to have tests for both branch of the expression. Have you looked into why the negate condition mutator failed to identify this problem in your project? |
My explanation was that the mutations Stryker performs simply do not mutate the code in the way proposed, and all the mutations it does are not sufficient to find the missing test. As the actual code is a bit different from the example I showed in my first post, I've created a simple example project that you can check for yourself: The method I'm testing: namespace MutatorExample
{
public static class Class1
{
public static string AddImagePrefix(string logo)
{
logo = logo.Contains("data:image/jpg;base64,")
? logo
: $"data:image/jpg;base64,{logo}";
return logo;
}
}
} The test for it: namespace MutatorExampleTests
{
using FluentAssertions;
using MutatorExample;
public class Tests
{
[SetUp]
public void Setup()
{
}
[Test]
[TestCase("a")]
[TestCase("any")]
[TestCase("any base64 coded string")]
[TestCase("any base64 coded string, that is a bit longer then that before")]
public void AddImageprefix_ReturnsBase64String(string originalString)
{
// Arrange
// Act
var result = Class1.AddImagePrefix(originalString);
// Assert
result.Should().BeEquivalentTo($"data:image/jpg;base64,{originalString}");
}
}
} Stryker only does mutate the strings or negates the condition, but that does not fetch the missing test. |
thanks for the explanation. Yes indeed! There are 3 possible situations here:
You are right, it seems a dedicated mutator is revelant. I suggest then that you remove support for conditional expressions from the Negate condition mutator, as those mutants would be less interesting than the new ones. |
@dupdob |
yes, this will avoid having duplicate/similar mutants |
Cool stuff! It took me a while to understand the missing piece here so here is the mutated code that Stryker wouldn't flag:
Missing tests would be
|
As I do not see any changes here, I suspect that nothing was changed yet, even though @michalusio proposed to try to add this if there are no objections. Is something missing, or did none get around to do this yet? |
Hi @causa-prima ! |
Is your feature request related to a problem? Please describe.
I have some code that prefixes a string conditionally:
I have a test that checks that some strings without that prefix get prefixed, but I do not have any test that checks whether already prefixed strings also get that prefix added. Stryker didn't find that issue as I expected it to.
Describe the solution you'd like
I propose adding two mutations for the conditional (ternary) operator:
Original:
a ? b : c
Mutation 1:
b
Mutation 2:
c
Describe alternatives you've considered
I can't think of any.
Additional context
None.
The text was updated successfully, but these errors were encountered: