软件测试——第一次实验

一、Install Junit(4.12), Hamcrest(1.3) with Eclipse

jar包就是别人已经写好的一些类,然后将这些类进行打包,可以将这些jar包引入项目中,然后就可以直接使用这些jar包中的类和属性以及方法。

 

 

Eclipse中引入jar包参考这个链接:http://blog.csdn.net/mazhaojuan/article/details/21403717

 

介绍链接中的第二种方法:用户jar包式

通过“项目”->“属性”->“Java构建路径”->“添加库”->“用户库”->“新建”->填写用户库名称,点击“OK”->“添加外部jar包”(“也可以选择多个jar,但是限制在同一个文件夹中”)。

这种方式的好处是,不用每次创建项目都要引入jar包。

 

二、Install Eclemma with Eclipse

通过eclipse安装非常简单,“帮助”->“eclipse marketplace”,搜索 eclemma,一路默认安装就好了。

 

 

 

三、Write a java program for the triangle problem and test the program with Junit

a) Description of triangle problem:

Function triangle takes three integers a,b,c which are length of triangle sides; calculates whether the triangle is equilateral, isosceles, or scalene.

判断三角形的思路:

1)  是否满足“两条边之和大于第三边”

2)  最后判断是哪种类型的三角形。先判断是否是等边三角形,再判断是否是等腰三角形,最后“不等边三角形”

四、关键代码

package lib1;

 

public class Triangle {

     public static String triganles (int a, int b, int c){

            if(a+b > c && a+c > b && b+c > a){

            if (a == b && b == c)

                return "this is a equilateral triganle!";

            else if (a == b || b == c || c == a)

                return "this is a isosceles triganle!";

            else

                return "this is a scalene triganle!"; 

            }

            else

            return "this is not triganle!";

        }

 

}

 

 

 

 

package lib1;

 

import static org.junit.Assert.*;

 

import org.junit.Test;

 

public class TestTriangle {

 

    @Test

    public void testTriangle() {

        assertEquals("this is not triganle!",new Triangle().triganles(1,2,3));

        assertEquals("this is a equilateral triganle!",new Triangle().triganles(1,1,1));

        assertEquals("this is a isosceles triganle!",new Triangle().triganles(2,2,3));

        assertEquals("this is a scalene triganle!",new Triangle().triganles(2,3,4));

    }

 

}

五、使用EclEmma进行简单地覆盖测试

 

 

由图可以看出,测试覆盖率为100%。

转载于:https://www.cnblogs.com/jinteng/p/8642432.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值