首页 > 其他 > 详细

软件测试——第一次实验

时间:2018-03-25 10:27:26      阅读:243      评论:0      收藏:0      [点我收藏+]

一、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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!