简体   繁体   English

如何在 java 中为 hashcode() 方法编写 ptest(变异测试)

[英]How to write pitest(mutation test) for hashcode() method in java

I am writing mutation test for hashcode method.我正在为哈希码方法编写突变测试。 Below is my piece of code下面是我的一段代码

@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;
 }

Does anyone know how I can write the mutation test for this code?有谁知道我如何为这段代码编写突变测试?

Unless you have very specific requirements for how your hashcode should perform, EqualsVerifier is usually sufficient to ensure it behaves sensibly (in tandem with the equals implementation).除非您对哈希码的执行方式有非常具体的要求,否则 EqualsVerifier通常足以确保其行为合理(与 equals 实现相结合)。

Please note however that you do not "write mutation tests" for the code, instead pitest (and other mutation testing tools) verify how effective the existing unit tests are.但是请注意,您不会为代码“编写变异测试”,而是 ptest(和其他变异测试工具)验证现有单元测试的有效性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM