如果您真的想测试示例中的所有内容,请尝试更多测试……
public void testIncludes7() throws Exception {
Range range = new Range(0, 5);
assertFalse(range.includes(7));
}
public void testIncludes5() throws Exception {
Range range = new Range(0, 5);
assertTrue(range.includes(5));
}
public void testIncludes0() throws Exception {
Range range = new Range(0, 5);
assertTrue(range.includes(0));
}
public void testEncompassInc7() throws Exception {
Range range = new Range(0, 5);
range.encompass(7);
assertTrue(range.includes(7));
}
public void testEncompassInc5() throws Exception {
Range range = new Range(0, 5);
range.encompass(7);
assertTrue(range.includes(5));
}
public void testEncompassInc0() throws Exception {
Range range = new Range(0, 5);
range.encompass(7);
assertTrue(range.includes(0));
}
因为否则,您会错过很多错误的可能性...例如,在包含之后,范围仅包括7,等等...还对范围的长度进行了测试(以确保不包含随机值),并且另一组完全试图将范围5包含在内的测试...我们期望什么-包含范围中的异常或范围未更改?
无论如何,关键是您要检验的行为中是否有任何假设,将其置于自己的测试中,是吗?