【问题标题】:How to write pitest(mutation test) for hashcode() method in java如何在 java 中为 hashcode() 方法编写 ptest(mutation test)
【发布时间】:2021-05-31 21:23:59
【问题描述】:

我正在为 hashcode 方法编写变异测试。下面是我的一段代码

@Override
 public int hashCode() {
  final int prime = 31;
  int result = 1;
  result = (prime * result)+ privateVariable.hashcode();   
  result = (prime * result)+ ((this.details == null) ? 0 : this.details.hashCode());
  result = (prime * result)+ ((this.status == null) ? 0 : this.status.hashCode());
  return result;
 }

有谁知道我如何为这段代码编写变异测试?

【问题讨论】:

    标签: java junit4 mutation pitest


    【解决方案1】:

    除非您对哈希码的执行方式有非常具体的要求,否则EqualsVerifier 通常足以确保其行为合理(与 equals 实现相结合)。

    但请注意,您不会为代码“编写变异测试”,而是最简单(和其他变异测试工具)验证现有单元测试的有效性。

    【讨论】:

    • 感谢亨利的回复。我不能使用 EqualsVerfier api 来测试编写变异测试覆盖率
    猜你喜欢
    • 1970-01-01
    • 2018-06-07
    • 2019-09-30
    • 2019-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-03
    相关资源
    最近更新 更多