软件测试第一次实验实验报告

IDE:IntelliJ IDEA

1、安装Junit(4.12), Hamcrest(1.3)

File --> Project Structure --> Modules

点击加号添加jar包

应用后确定

 

2、编写程序

 1 /**
 2  * Created by wuzhuo on 17/3/5.
 3  */
 4 public class Test0 {
 5 
 6     //a,b,c 三角形的三边
 7     public boolean isTriangle(int a, int b, int c) {
 8         if (a+b>c && a+c>b && b+c>a) {
 9             return true;
10         } else {
11             return false;
12         }
13     }
14 
15     //是否等边
16     public boolean isEquilateral(int a, int b, int c) {
17         if (a==b && a==c && b==c) {
18             return true;
19         } else {
20             return false;
21         }
22     }
23 
24     //是否等腰
25     public boolean isIsosceles(int a, int b, int c) {
26        if (isTriangle(a,b,c)) {
27            if (a==b || a==c || b==c) {
28                return true;
29            } else {
30                return false;
31            }
32        } else {
33            return false;
34        }
35     }
36 
37     //三边都不想等
38     public boolean isScalene(int a, int b, int c) {
39        if (isTriangle(a,b,c)) {
40            if (a!=b && a!=c && b!=c) {
41                return true;
42            } else {
43                return false;
44            }
45        } else {
46            return false;
47        }
48     }
49 }

 

3、编写测试程序

 1 import org.junit.After;
 2 import org.junit.Before;
 3 import org.junit.Test;
 4 
 5 import static org.junit.Assert.*;
 6 
 7 /**
 8  * Created by wuzhuo on 17/3/10.
 9  */
10 public class Test0Test {
11     private Test0 testTraingle;
12     @Before
13     public void setUp() throws Exception {
14         testTraingle = new Test0();
15     }
16 
17     @After
18     public void tearDown() throws Exception {
19 
20     }
21 
22     @Test
23     public void isTriangle() throws Exception {
24         assertEquals(false, testTraingle.isTriangle(1,2,3));
25         assertEquals(true,testTraingle.isTriangle(1,1,1));
26     }
27 
28     @Test
29     public void isEquilateral() throws Exception {
30         assertEquals(true, testTraingle.isEquilateral(1,1,1));
31         assertEquals(false,testTraingle.isEquilateral(1,3,3));
32     }
33 
34     @Test
35     public void isIsosceles() throws Exception {
36         assertEquals(false, testTraingle.isIsosceles(1,1,2));
37         assertEquals(false,testTraingle.isIsosceles(2,3,4));
38         assertEquals(true,testTraingle.isIsosceles(1,3,3));
39     }
40 
41     @Test
42     public void isScalene() throws Exception {
43         assertEquals(false, testTraingle.isScalene(1,1,2));
44         assertEquals(false, testTraingle.isScalene(1,3,3));
45         assertEquals(false, testTraingle.isScalene(1,1,1));
46         assertEquals(true, testTraingle.isScalene(2,3,4));
47     }
48 
49 }

 

4、结果截图

 

绿色:全部覆盖

黄色:部分覆盖

红色:没有覆盖

posted @ 2017-03-10 11:37  dawn1227  阅读(252)  评论(0编辑  收藏  举报