A mutation is not killed when it should be using a method with an automatically entered field

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]; /* * Unsetting a property is done by changing the current property to null. * Technically, the old property doesn't get changed, a new one is inserted with * a higher revision number, and it becomes the canonical one. */ 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; // ... SNIP ... @Test public void testCallsSetPropertyWithCorrectParameters() throws SQLException, TaboolaException { final String[] args = new String[]{"publisher", "version", "mode", "property"}; final String output = unsetProperty.parse(args); verify(setProperty).setProperty("publisher", "version", "mode", "property", null, false); // The above line should have killed the mutation! verifyNoMoreInteractions(setProperty); assertThat(output).isEqualTo(""); } } 

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.

+8
java spring spring-boot mutation-testing pitest
source share

No one has answered this question yet.

See related questions:

836
Java: when to use static methods
828
When and how should the ThreadLocal variable be used?
617
What issues should be considered when redefining peers and hashCode in Java?
3
Spring Security with OpenIDAuthenticationFilter Issue
2
Autowired bean is null in MVC Controller
one
Configuration values ​​do not load when testing a private method
one
spring boot How to clean a bean file using yaml file in src / test / resource /
one
Java ResourceBundles not reading utf-8 characters correctly - after updating Eclipse
one
OGNL setValue target - null
one
Killing mutations

All Articles