Java 当应该使用自动注入字段的方法时,突变不会被杀死
我有以下资料:Java 当应该使用自动注入字段的方法时,突变不会被杀死,java,spring,spring-boot,mutation-testing,pitest,Java,Spring,Spring Boot,Mutation Testing,Pitest,我有以下资料: 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.
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 "";
}
}
正如预期的那样,测试通过了。当我运行它通过坑,我得到以下结果
33 1. removed call to my/package/SetProperty::setProperty → SURVIVED
第33行在类代码中突出显示
检查的试验如下:
(32毫秒)my.package.UnsetPropertyTest.testCallsSetPropertyWithCorrectParameters(my.package.UnsetPropertyTest)
(3毫秒)my.package.UnsetPropertyTest.TestUnsetThrowForIncorrectNumberOfParameters(my.package.UnsetPropertyTest)
- 当我更改测试调用参数(
)时,测试失败。果然args
- 当我更改断言(
)参数时,测试失败。正如所料verify(setProperty).setProperty(…)
- 当我手动注释掉第一个代码块中突出显示的函数调用时,测试失败
我正在使用Java8、Mockito1.9.5和Pit1.1.4 几年后,似乎没有人提到(Spring)
@Resource
和(Mockito)@injectmock
是相互排斥的解决方案。游戏中有多个生成的UnsetProperty
子类,因此PIT对正在发生的事情感到困惑。html报告的“测试检查”部分是否列出了UnsetPropertyTest?@henry Yes。我已经用列出的测试更新了我的问题。这个类中的其他突变是否如预期的那样被杀死?@henry是的,这个方法中还有两个突变被正确杀死。你能把它细化到一个复制这个问题的最小项目吗?我不再能够测试你的答案(4.5年是很长的一段时间),但希望其他人也会面临同样的问题。
33 1. removed call to my/package/SetProperty::setProperty → SURVIVED