软件测试:lab1.Junit and Eclemma

Task:

  1. Install Junit(4.12), Hamcrest(1.3) with Eclipse
  2. Install Eclemma with Eclipse
  3. 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.

Report:

  Junit:http://mvnrepository.com/artifact/junit/junit/4.12

  Hamcrest:http://mvnrepository.com/artifact/org.hamcrest/hamcrest-all/1.3

  Eclemma:https://sourceforge.net/projects/eclemma/

  1. Junit(4.12), Hamcrest(1.3)安装与配置

   eclipse中新建Java项目scs2015,再在该项目下新建目录lib,将hamcrest-all-1.3.jar,junit-4.12.jar拷贝到lib目录下,并导入项目里;

  2. Eclemma的安装与配置

   eclipse中—点击Help菜单—Install New Software,在弹出的对话框中,点击Add,之后点击 Archive,找到你下载好的 Eclemma.zip 资源文件,按照提示一步一步的安装重新启动 eclipse就完成了;

  3. Test triangle program with Junit

   点击安装Eclemma后工具栏上新增的覆盖测试按钮,来使用Eclemma测试Java程序

   

   测试结果如上图所示。

   在 Java 编辑器中,EclEmma 用不同的色彩标示了源代码的测试情况。其中,绿色的行表示该行代码被完整的执行,红色部分表示该行代码根本没有被执行,而黄色的行表明该行代码部分被执行。黄色的行通常出现在单行代码包含分支的情况,例如上图中的 20 行就显示为黄色。

   除了在源代码编辑窗口直接进行着色之外,EclEmma 还提供了一个单独的视图来统计程序的覆盖测试率。

   由于Triangle.java中还有一些get set 方法行没有被测试覆盖,上图Coverage为52.6%,尝试删去多余代码行后视图显示如下:

   代码附录:

   Triangle.java

public class Triangle {
    private double side1,side2,side3;

    public Triangle(double side1, double side2, double side3) {
        super();
        this.side1 = side1;
        this.side2 = side2;
        this.side3 = side3;
    }

    public String getShape() {
        String sha[]= {"equilateral","isosceles", "scalene"};
        int i=-1;
        if(this.side1!=this.side2&&this.side1!=this.side3&&this.side2!=this.side3) {
            i=2;
        }else if(this.side1==this.side2&&this.side2==this.side3) {
            i=0;
        }else {
            i=1;
        }
        return sha[i];
    }
}

   TriangleTest.java

public class TriangleTest {

    @Test
    public void testEquilateral() {
        double a1=1,a2=1,a3=1;
        Triangle tria=new Triangle(a1, a2, a3);
        assertEquals("equilateral",tria.getShape());
    }

    @Test
    public void testIsosceles() {
        double b1=1,b2=1,b3=1.2;
        Triangle trib=new Triangle(b1, b2, b3);
        assertEquals("isosceles",trib.getShape());
    }

    @Test
    public void testScalene() {
        double c1=3,c2=4,c3=5;
        Triangle tric=new Triangle(c1, c2, c3);
        assertEquals("scalene",tric.getShape());
    }

}

    

软件测试:lab1.Junit and Eclemma的更多相关文章

  1. 软件测试Lab 1 Junit and Eclemma

    首先安装eclipse 然后下载hamcrest-core-1.3.jar,下载地址:http://mvnrepository.com/artifact/org.hamcrest/hamcrest-c ...

  2. ST Lab1 junit test

    代码地址:  https://github.com/newff/st-lab1 Tasks: Install Junit(4.12), Hamcrest(1.3) with Eclipse Insta ...

  3. 单元测试系列:如何使用JUnit+JaCoCo+EclEmma完成单元测试

    更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢!   原文链接:http://www.cnblogs.com/zishi/p/6726664.html -----如 ...

  4. 使用junit和eclemma进行简单的代码测试

    1.Junit和Hamcrest的安装 可以在https://mvnrepository.com/上面下载所需要的Junit和Hamcrest的jar包,然后在项目中新建一个lib文件夹,将下载好的j ...

  5. 【软件测试】Junit入门

    写在前面:本博客为本人原创,严禁任何形式的转载!本博客只允许放在博客园(.cnblogs.com),如果您在其他网站看到这篇博文,请通过下面这个唯一的合法链接转到原文! 本博客全网唯一合法URL:ht ...

  6. Software Testing Techniques LAB 01: test Junit and Eclemma

    1. Installing  1. Install Junit and hamcrest First, I download the Junit-4.12.jar and hamcrest-core- ...

  7. 软件测试作业3 — PrintPrimes()

    一.Use the following method printPrimes() for questions a–d. (a) Draw the control flow graph for the p ...

  8. 软件测试-homework3

    printPrime()代码: public static void printPrimes (int n) { int curPrime; // Value currently considered ...

  9. 软件测试技术作业3---PrintPrimes()

    一.代码部分: private static void printPrimes (int n) { int curPrime; // Value currently considered for pr ...

随机推荐

  1. css内外边距属性

    盒子模型: 所有HTML元素可以看作盒子,在CSS中,"box model"是用来设计和布局时 使用. CSS盒模型本质上是一个盒子, 封装周围的HTML元素, 它包括:边距,边框 ...

  2. c#获取url请求的返回值

    /// <summary> /// 获取url的返回值 /// </summary> /// <param name="url">eg:http ...

  3. redux源码图解:createStore 和 applyMiddleware

    在研究 redux-saga时,发现自己对 redux middleware 不是太了解,因此,便决定先深入解读一下 redux 源码.跟大多数人一样,发现 redux源码 真的很精简,目录结构如下: ...

  4. vue 数字随机滚动(数字递增)

    html: <span v-for="i in numArr">{{i}}</span>   data: numArr: [], methods: perN ...

  5. APNs

    生成推送证书: 1. 登陆开发者中心:https://developer.apple.com2. 点开 certificates.identifiers 和 proversionprofiles 里面 ...

  6. OSI七层网络模型浅析

    OSI七层网络模型(从下往上): 物理层(Physical):设备之间的数据通信提供传输媒体及互连设备,为数据传输提供可靠的 环境.可以理解为网络传输的物理媒体部分,比如网卡,网线,集线器,中继器,调 ...

  7. 安装Oracle数据库心得

    学到Oracle数据库了,想在自己电脑上安装个Oracle数据库.在网上下载了一个Oracle18c版 下边是我安装Oracle18c版的数据库失败,后来在卸载过程中遇到的问题: 1.用Univers ...

  8. FlexRay通信机制

    通信周期是 FlexRay 的基本通信单元[6~7,19].每个通信周期包括四个时间层,如图 2-9 所示.通信周期由静态段(Static Segment).动态段(Dynamic Segment). ...

  9. WMI tester

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  10. Vue2.5基础

    1.1 创建第一个Vue实例 官方网站:https://cn.vuejs.org 学习 --> 安装 刚开始学习Vue,使用最简单的安装方式,直接用<script>引入 我们下载开发 ...