无效问题:布尔值将整数大小的值的返回替换为(x==0?1:0)→幸存下来



更新:自从这个问题发布后,突变覆盖失败就消失了,可能是因为维修站的错误修复?

所以这个问题现在是无效的。我不知道在这种情况下该怎么办。删除问题?把它留在这里?

我正在使用pit进行突变测试。有一个僵尸在一个非常简单的功能:

public boolean isAuthenticated() {
return true;
}

它使用进行测试

assertEquals(true, isAuthenticated());

但我得到错误replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED

我确实尝试过用System.identityHashCode((检查身份,但没有帮助。

有办法杀死这个僵尸吗?如果没有,我如何关闭对布尔值或这行代码的特定检查?

我认为这个错误并没有揭示问题的根源,在我的情况下(很可能在任何情况下(都不可能做到这一点。

在我的例子中,我有一个对象列表,其中包含一个返回谓词的函数。因此,我使用stream对所有这些对象进行迭代,并筛选出其中一个与谓词匹配的对象作为候选对象。所以就我的代码而言:

public List<ParkingSlot> getFreeParkingSlots(List<DepartmentParkingRule> ruleList, Employee candidate){
return 
ruleList.stream().
.filter(j -> j.getPredicate().test(candidate)) // <-- here appeared the error *replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED*
.map(t -> t.getFreeParkingSlots(candidate))
.findFirst()
.orElseThrow(new NotMatchedException(candidate));
}

我(通过分析/设计(期望一名候选员工只符合一条部门规则。我认为使用.findFirst()非常合适。PIT被拒绝。通过将一个通常不匹配的案例(部门(的谓词结果突变为"突变匹配",可能会有多个匹配,而不是一个。

所以我修改了我的代码,以便在有多个匹配的情况下抛出一个异常。在这种变化之后,突变体被杀死了。所以我现在的功能是:

public List<ParkingSlot> getFreeParkingSlots(List<DepartmentParkingRule>  ruleList,
Employee candidate){
Optional<List<ParkingSlot>> parkingSlots = ruleList.stream().
.filter(j -> j.getPredicate().test(candidate)) 
.map(t -> t.getFreeParkingSlots(candidate))
.reduce((anElement, otherElement) -> 
throw new DuplicateException());//reduce is executed when a possible false positive duplicate rule match
if (parkingSlots.isPresent() && CollectionUtils.isNotEmpty(parkingSlots.get())){
return parkingSlots.get();
}else {
throw new NotMatchedException(candidate);
}
}

因此,错误replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED表明发生了突变,最重要的是,这种突变没有导致我的测试失败。

下次我看到这个错误时,我将关注对整个测试的影响,而不是特定的布尔函数。

需要注意的是,上面的代码不是真实的,但对于展示如何解释错误和修改源代码的操作非常有用。改变检测方法可能有助于杀死变异株,但这取决于每种情况。

希望它能帮助到别人。

最新更新