软件测试: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. Mac 安装Python3 facewap环境

    参考网上大神的方法 1 官网下载安装 2 下载指定版本的源码cmake安装 3 Mac上使用homebrew进行安装(强烈推荐,主要是前两种的openssl模块我没有搞定链接什么的一直报错,一个个下载 ...

  2. TypeScript 类型定义文件(*.d.ts)自动生成工具

    在开发ts时,有时会遇到没有d.ts文件的库,同时在老项目迁移到ts项目时也会遇到一些文件需要自己编写声明文件,但是在需要的声明文件比较多的情况,就需要自动生产声明文件.用过几个库.今天简单记录一下. ...

  3. Oracle数据仓库套件

    OBIEE RPD:定义不同分析的主题角度,确定相应的事实表和维度表 报表层:选取需要的维度和度量,根据筛选器选取需要的数据 可视化:用图形展示数据,支持常见的图形:如折线图,饼图,堆叠图等. ODI ...

  4. timestamp时间格式

    时间戳(timestamp),通常是一个字符序列,唯一地标识某一刻的时间. 时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的 ...

  5. 并发编程心得--synchronized

    根据业务需求解决并完善并发问题-- IWMS仓库系统不考虑并发那么大的情况下,我想到的有2种并发解决方案. 1.在同时请求时,给需要操作的保存接口添加synchronized 同步方式,同步保存方法, ...

  6. SQA计划

    一.SQA计划 1.软件工程 所做程序是一个长沙大学的学习app系统 .可以实现用户的注册登录,课程学习,以及活动参加.根据需求建模,进行体系结构设计,然后设计. 2.质量保证 (1)项目需要符合IE ...

  7. anki_vector SDK源码解析(教程)

    一:最近anki vector robot开放了Python SDK,我听到的第一时间就赶快上网查了查,先抛几个官网重要链接吧: Python编程API手册及环境搭建等: https://sdk-re ...

  8. ANSYS中的阻尼damper

    详情请见链接: ANSYS中的阻尼 ANSYS动力学分析中的阻尼

  9. 反向Ajax:WebSocket

    郭晨 软件151 1531610114 WebSocket 在HTML5中出现的WebSocket是一种比Comet还要新的反向Ajax技术,WebSocket启用了双向的全双工通信信道,许多浏览器( ...

  10. 常识判断-科技-day123

    PS: 在常识中科技是最难的 PS: 20-2w  HZ是人能听到的频率 PS: 物体的熔点和凝固点是一致的 PS: 氮肥如果多了,可能只是长叶子不结果: 磷肥促进开花结果 PS; 病毒是介于生物和非 ...