Paweł Sawicz
Twitter : @sawiczpawel LinkedIn :http://tiny.cc/7zvjqw
@sawiczpawel
http://pawel.sawicz.eu
Co to są testy mutacyjne ?
Dla czego powinniśmy się tym przejmować ?
Kiedy powinno się używać testów mutacyjnych ?
"In biology, a mutation is a permanent change of the nucleotide sequence of the genome of an organism, virus, or extrachromosomal DNA or other genetic elements" - via wikipedia.com
In technology, a mutation is a permanent change of an instruction in a function of a program.
1971 - Richard Lipton
1980 - Timothy Budd
public int CalculateCO2Emmision(int engineSize)
{
if (engineSize < 4)
{
return 200;
}
else
{
return 400;
}
}
public void CalculateCO2Emmision_EngineSize3_Return200()
{
//arrange
var checker = new SimpleIf();
//act
var result = checker.CalculateCO2Emmision(3);
//assert
Assert.AreEqual(200, result);
}
public int CalculateCO2Emmision(int engineSize)
{
if (engineSize <= 4)
{
return 200;
}
else
{
return 400;
}
}
public void CalculateCO2Emmision_EngineSize3_Return200()
{
//arrange
var checker = new SimpleIf();
//act
var result = checker.CalculateCO2Emmision(3);
//assert
Assert.AreEqual(200, result);
}
[Test]
[TestCase(3, 200)]
[TestCase(4, 400)]
[TestCase(5, 400)]
public void CalculateCO2Emmision_EngineSize3_Return200_BestOne
(int engineSize, int expectedC02)
{
//arrange
var checker = new SimpleIf();
//act
var result = checker.CalculateCO2Emmision(engineSize);
//assert
Assert.AreEqual(expectedC02, result);
}
public int CalculateCO2Emmision(int engineSize)
{
if (engineSize <= 4)
{
return 200;
}
else
{
return 400;
}
}
Mutant
public int CalculateCO2Emmision(int engineSize)
{
if (engineSize < 4)
{
return 200;
}
else
{
return 400;
}
}
Mutant runner + ILSpy demo
In technology, a mutation is a permanent change of an instruction in a function of a program.
Traditional code coverage tools measure test coverage of the code, not business intent
Mutation runner + ILSpy
Mutation runner + ILSpy
.NET :
Ruby :
Java :
@sawiczpawel, pawel@sawicz.eu
By Paweł Sawicz