必做一
测试用例 | ||
序号 | 测试输入三条边(a,b,c) | 测试预言(Oracle:不是三角形,不等边,等腰,等边三角形 |
1 | 3,4,5 | 不等边 |
2 | 5,6,6 | 等腰 |
3 | -1,3,4 | 不是三角形 |
4 | 6,-5,7 | 不是三角形 |
5 | 6,6,6 | 等边 |
6 | 3,3,3 | 不等边 |
7 | 0,5,7 | 不等边 |
8 | 6,5,4 | 等边 |
必做二
1 package 三角形; 2 3 import static org.junit.Assert.*; 4 5 import org.junit.Test; 6 7 public class TestTriangle{ 8 @Test 9 public void testIsTriangle1(){ 10 Triangle t = new Triangle(3,4,5); 11 assertEquals(t.getType(t),"Scalene"); 12 } 13 14 @Test 15 public void testIsTriangle2(){ 16 Triangle t = new Triangle(5,6,6); 17 assertEquals(t.getType(t),"Isoceles"); 18 } 19 20 @Test 21 public void testIsTriangle3(){ 22 Triangle t = new Triangle(-1,3,4); 23 assertEquals(t.getType(t),"Illegal"); 24 } 25 @Test 26 public void testIsTriangle4(){ 27 Triangle t = new Triangle(6,-5,7); 28 assertEquals(t.getType(t),"Illegal"); 29 } 30 @Test 31 public void testIsTriangle5(){ 32 Triangle t = new Triangle(6,6,6); 33 assertEquals(t.getType(t),"Regular"); 34 } 35 @Test 36 public void testIsTriangle6(){ 37 Triangle t = new Triangle(3,3,3); 38 assertEquals(t.getType(t),"Scalene"); 39 } 40 @Test 41 public void testIsTriangle7(){ 42 Triangle t = new Triangle(0,5,7); 43 assertEquals(t.getType(t),"Scalene"); 44 } 45 @Test 46 public void testIsTriangle8(){ 47 Triangle t = new Triangle(6,5,4); 48 assertEquals(t.getType(t),"Regular"); 49 } 50 }
必做三
这次使用了Junit功能,使用测试类的assertEquals方法来判断结果,测试的结果和自己的预想一致,学习到以前从没用过的新功能。