[必做题1] 针对附录1给出的三角形判断Java 代码,应用等价类划分法设计测试用例,用表格形式列出设计的测试用例,写到博客中。
序号 | 测试输入:三条边(a,b,c) |
测试预言:Oracle:Illegal(非三角形),Scalene(一般三角形), Isoceles(等腰三角形),Regular(等边三角形) |
1 | (2,3,4) | Scalene |
2 | (3,4,5) | Scalene |
3 | (0,0,1) | Illegal |
4 | (5,5,10) | Illegal |
5 | (5,5,6) | Isoceles |
6 | (5,5,5) | Regular |
7 | (5,6,7) | Scalene |
[必做题2] 模仿附录2给出的三角形判断Junit测试代码,设计单元测试脚本,测试 [必做题1]设计得到的测试用例。注意测试脚本中测试用例出现顺序与[必做题1]表格所列顺序一致。运行所得的测试脚本,截运行结果图,写到博客中,同时将源代码commit到你自己的github
import static org.junit.Assert.*; import org.junit.Test; public class TestTriangle { @Test public void testIsTriangle1(){ Triangle t = new Triangle(2,3,4); assertEquals(t.getType(t),"Scalene"); } @Test public void testIsTriangle2(){ Triangle t = new Triangle(3,4,5); assertEquals(t.getType(t),"Scalene"); } @Test public void testIsTriangle3(){ Triangle t = new Triangle(0,0,1); assertEquals(t.getType(t),"Illegal"); } @Test public void testIsTriangle4(){ Triangle t = new Triangle(5,5,10); assertEquals(t.getType(t),"Illegal"); } @Test public void testIsTriangle5(){ Triangle t = new Triangle(5,5,6); assertEquals(t.getType(t),"Isoceles"); } @Test public void testIsTriangle6(){ Triangle t = new Triangle(5,5,5); assertEquals(t.getType(t),"Regular"); } @Test public void testIsTriangle7(){ Triangle t = new Triangle(5,6,7); assertEquals(t.getType(t),"Scalene"); } }
运行结果图:,和预期结果相一致
我的Github链接:https://github.com/Xuhongke
[必做题3] 心得体会。写下本次练习你收获的知识点
对于在Java中进行Juit测试,一开始其实并不会,后来上网查阅了相关的资料后大致了解了,自己定义了一个测试类完成了测试,并且一开始因为使用assertFalse函数还产生了一些错误。