我正在试验junit5和pitest。我的测试代码如下所示:
// [...]
InputStream istream = this.getClass().getResourceAsStream("/" + file.getName());
if (istream == null) // 1. negated condition -> suvived
{
istream = Files.newInputStream(this.files.get(varname).toPath(), StandardOpenOption.READ);
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(istream, StandardCharsets.UTF_8))) // 2. removed call to java/io/BufferedReader::close → SURVIVED // 3. removed call to java/lang/Throwable::addSuppressed → SURVIVED
{
// [...]
} // 4. removed call to java/io/BufferedReader::close → SURVIVED
在这个小代码块中,我留下了 4 个我想杀死的幸存突变。杀死可能通过添加/更改测试或重构代码来发生。
我现在的问题是第一个突变是一个等效的突变 - 我不知道如何重构它。其他三个突变是由 try-resource-statement 隐含的。
所以我的问题是如何重构这 4 个突变?因为我确信他们不能被附加/更改的测试杀死。