简体   繁体   中英

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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