【发布时间】:2018-10-20 00:12:46
【问题描述】:
刚接触代码覆盖率,想了解一些见解...
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Person other = (Person) obj;
if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
return false;
}
if ((this.email == null) ? (other.email != null) : !this.email.equals(other.email)) {
return false;
}
if (this.age != other.age && (this.age == null || !this.age.equals(other.age))) {
return false;
}
return true;
}
我如何在 jcoco 代码覆盖率中涵盖这一点。
【问题讨论】:
-
我不明白你的问题。请详细说明。
-
我真的很抱歉造成混乱,我正试图在代码覆盖范围内覆盖这段代码,并了解如何做到这一点?我正在尝试编写一个覆盖此代码的测试用例。
-
从技术上讲,您需要 7 种测试方法来测试您的
equals(),并使用不同类型的参数来涵盖所有 ifs -
@Ivan 我写的最多,但我在写最后 3 个名字、电子邮件和年龄时遇到问题。你能帮忙吗?
-
1.比较两个不同名字的人。 2. 比较姓名相同但邮件不同的人。 3. 比较姓名和邮件相同但年龄不同的人。 4. 比较具有相同领域的人
标签: java junit code-coverage