简体   繁体   English

C# Stryker 变异框架

[英]C# Stryker Mutation Framework

I am new to testing and writing unit tests.我是测试和编写单元测试的新手。 I came upon this mutation framework called Stryker.我遇到了这个叫做 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.在某些测试用例突变期间,我遇到了 Equality Mutation 或 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.我很高兴变异测试可以帮助您学习单元测试,这就是我帮助构建 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我们将<变异为<=>以查看您是否为 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如果您对 Stryker 有任何疑问,请查看文档或查看这篇很棒的博客文章: 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!如果您认为文档不足,请提交一个我们可以改进的问题!

Have you seen the docs?你看过文档吗? https://github.com/stryker-mutator/stryker-handbook/blob/master/mutator-types.md https://github.com/stryker-mutator/stryker-handbook/blob/master/mutator-types.md

more specifically:进一步来说:

  1. https://github.com/stryker-mutator/stryker-handbook/blob/master/mutator-types.md#equality-operator https://github.com/stryker-mutator/stryker-handbook/blob/master/mutator-types.md#equality-operator

Equality Mutation changes between the current comparison operator with one of the many available (>, <, >=, <=, ==, !=) Equality Mutation 在当前比较运算符与许多可用 (>, <, >=, <=, ==, !=) 之一之间发生变化

  1. https://github.com/stryker-mutator/stryker-handbook/blob/master/mutator-types.md#string-literal https://github.com/stryker-mutator/stryker-handbook/blob/master/mutator-types.md#string-literal

String mutator basically changes a String. String mutator 基本上改变了一个字符串。 If you throw an exception with message "Exception because X" , it may change the message to something different "Exception because Y" , or "A completely different message"如果您抛出一个带有消息"Exception because X" ,它可能会将消息更改为不同的"Exception because Y""A completely different message"

IMHO String Mutator is usually useless.恕我直言,String Mutator 通常没用。 I never assert on String messages (I rely on Exception types), but Equaly Mutator is one of the most classic, easy, and useful mutator that exists我从不断言字符串消息(我依赖于异常类型),但 Equaly Mutator 是现存最经典、最简单、最有用的 Mutator 之一

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM