I have the following:
public class UnsetProperty extends Command { @Resource private SetProperty setProperty; public String parse(String[] args) { if (args.length != 4) { throw new RuntimeException("Incorrect number of arguments. Expected 4. Got " + args.length); } String publisher = args[0]; String version = args[1]; String mode = args[2]; String property = args[3]; setProperty.setProperty(publisher, version, mode, property, null, false); return ""; } }
and the following test:
public class UnsetPropertyTest extends CommandTest { @Configuration public static class Config { @Bean(name = "mockSetProperty") public SetProperty getSetProperty() { return mock(SetProperty.class); } @Bean public UnsetProperty getUnsetProperty() { return new UnsetProperty(); } } @Resource @InjectMocks private UnsetProperty unsetProperty; @Resource(name = "mockSetProperty") private SetProperty setProperty;
The test passes as expected. When I run it through PIT, I get the following result
33 1. removed call to my/package/SetProperty::setProperty → SURVIVED
Line # 33 is highlighted in the class code.
Verified Tests:
my.package.UnsetPropertyTest.testCallsSetPropertyWithCorrectParameters(my.package.UnsetPropertyTest) (32 ms)my.package.UnsetPropertyTest.testUnsetThrowsForIncorrectNumberOfParameters(my.package.UnsetPropertyTest) (3 ms)
Now:
- When I change the test call parameters (
args ), the test fails. As was expected - When I change the assertion arguments (
verify(setProperty).setProperty(...) ), the test fails. As expected. - When I manually comment on the function call highlighted in the first block of code, the test fails.
Why does a mutation survive?
I am using Java 8, Mockito 1.9.5 and PIT 1.1.4.
java spring spring-boot mutation-testing pitest
Madara uchiha
source share