作业8:单元测试练习(个人练习)
[必做题1] 针对附录1给出的三角形判断Java 代码,应用等价类划分法设计测试用例,用表格形式列出设计的测试用例,写到博客中。
| 序号 | 测试输入:三条边(a,b,c) | 测试预言(Oracle:直角、等腰、等边三角形) |
| 1 | (3,3,3,) | 等边三角形 |
| 2 | (3,4,5,) | 直角三角形 |
| 3 | (3,2,2) | 等腰三角形 |
[必做题2] 模仿附录2给出的三角形判断Junit测试代码,设计单元测试脚本,测试 [必做题1]设计得到的测试用例。注意测试脚本中测试用例出现顺序与[必做题1]表格所列顺序一致。
import static org.junit.Assert.*;
import org.junit.Test;
public class TestTriangle{
@Test
public void testIsTriangle1(){
Triangle t = new Triangle(3,3,3);
assertEquals(t.getType(t),"Regular");
}
@Test
public void testIsTriangle2(){
// according to the mutant, this test case should fail
Triangle t = new Triangle(3,4,5);
assertEquals(t.getType(t),"Scalene");
}
@Test
public void testIsTriangle3(){
Triangle t = new Triangle(3,2,2);
assertEquals(t.getType(t),"Isoceles");
}
}
测试结果:

[必做题3] 心得体会。写下本次练习你收获的知识点。
1.学会了如何用java编写一个判断三角形的程序。
2.学会了判断数据是否越界,两边只差是否大于第三边,接着在判断三角形类型,等边等腰,不等边。
GitHub:https://github.com/yuanchenhui/zuoye
浙公网安备 33010602011771号