I am new to testing and writing unit tests. I came upon this mutation framework called Stryker. I liked it as I am writing better test cases with it which helps me cover all use cases.
During some test cases mutation I come across Equality Mutation or String Mutation. I am confused on what these are?
Example
if (file.Length < 10) // Equality Mutation Here
{
throw new ArgumentException("The file name was too short", "file"); // String Mutation Here with the filename is too short
//throw new System.IO.FileNotFoundException();
}
What are these and why does it give it to me? Is there any significance?
I know my question may be very beginners level.
I'm glad mutation testing helps you learn unit testing, thats one of the reasons I helped build Stryker. To answer your question for this specific case:
if (file.Length < 10) // Equality Mutation Here
{
throw new ArgumentException("The file name was too short", "file"); // String Mutation Here with the filename is too short
//throw new System.IO.FileNotFoundException();
}
We mutate <
into <=
and >
to see if you wrote a test for the edge cases of
file.Length == 9
file.Length == 10
We mutate strings to see if you check the value of the string in your tests. For example, you could test if the message inside your exception is correct.
If you have any more questions about Stryker please check the documentation or see this great blog post: https://medium.com/swlh/mutation-tests-in-net-via-stryker-9fd9e8e4bcde
If you think the documentation is insufficient please submit an issue you we can improve!