美文网首页
软件测试实验报告一

软件测试实验报告一

作者: hdychi | 来源:发表于2018-03-22 12:05 被阅读0次

一、实验要求

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

Install Eclemma with Eclipse

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

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、Junit、Hamcrest、Eclemma的安装

使用了Idea作为IDE,引入了Junit4.8的Jar包。引入方法为:

File->Project Structrure->Libraries->+按钮->选择jar包->确定

对于Hamcrest,Junit4.4及以上已经集成了Hamcrest框架。由于我使用的是4.8版本,无需再安装

对于Eclemma,Idea自带的插件有Idea Code Coverage,不用再安装其他Code Coverage插件

2、判断三角形的代码

我的程序对于等边三角形返回1,对于非等边而等腰的三角形返回2,对于斜三角形返回3,对于不是三角形的返回4

package hdychi;

public class Triangle {
    public static int getType(int a,int b,int c){
        if(a == b && b == c){
            System.out.println(1);
            return 1;
        }
        else{
            if(a == b){
                if(a + b > c){
                    System.out.println(2);
                    return  2;
                }
            }
            else if(b == c){
                if(b + c > a){
                    System.out.println(2);
                    return 2;
                }
            }
            else if(a == c){
                if(a + c > b){
                    System.out.println(2);
                    return 2;
                }
            }
        }
        if(a + b > c && Math.abs(a - b) < c){
            System.out.println(3);
            return 3;
        }
        System.out.println(4);
        return 4;
    }
}

3、进行测试

我设计的样例包括等边三角形,三个不同两条边相等的等腰三角形
代码如下:

package hdychi;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

public class Test {
    @org.junit.Test
    public void testNormal(){
        int res1 = Triangle.getType(1,1,1);//测试等边三角形
        assertEquals(1,res1);
        int res2 = Triangle.getType(2,2,1);//测试等腰三角形
        assertEquals(2,res2);
        res2 = Triangle.getType(1,2,2);//换两条边等腰
        assertEquals(2,res2);
        res2 = Triangle.getType(2,1,2);//换两条边等腰
        assertEquals(2,res2);
        int res3 = Triangle.getType(3,4,5);//测试斜边三角形
        assertEquals(3,res3);
        int res4 = Triangle.getType(2,2,4);//测试不是三角形的
        assertEquals(4,res4);
        assertThat(res4,equalTo(4));
    }
}

4、测试结果

2018-03-22 12-04-04屏幕截图.png 2018-03-22 12-04-29屏幕截图.png

由图可见,测试覆盖率为97%,每个分支都达到了,且无错误

相关文章

  • 软件测试实验报告一

    一、实验要求 Install Junit(4.12), Hamcrest(1.3) with Eclipse In...

  • 软件性能测试目录

    软件性能测试Ⅰ 软件性能测试Ⅱ 软件性能测试Ⅲ 软件性能测试Ⅳ 软件性能测试Ⅴ 软件性能测试Ⅵ 软件性能测试Ⅶ 软...

  • 软件测试资料下载、【软件测试】新科海软件测试视频、04【软件测试

    ![软件测试资料下载、【软件测试】新科海软件测试视频、04【软件测试】播布客软件测试系列培训视频、08【软件测试】...

  • Bilateral Filter

    实验报告 专业:软件工程________姓名:陈锰____________学号:3170105197______日...

  • 软件测试概述

    通过本章的学习,您将学习到: 软件的定义 软件测试的历史 软件测试的定义 软件测试的对象 软件测试的意义 一、软件...

  • 软件测试常见的误区

    1.软件开发完成后进行软件测试 软件测试贯穿整个软件声明周期,需求测试和设计测试也是软件测试的一种,所以,软件...

  • 软件测试

    基础篇 软件测试历史 什么是软件测试 软件测试在整个开发过程中的地位 软件测试要素 软件测试类别 软件测试流程、软...

  • 软件测试概述

    软件测试学习笔记 第一部分:软件测试概述 什么是软件缺陷 软件缺陷来源 软件测试对象 软件测试过程模型 测试生命周...

  • 2G/3G/4G/5G,我所知道的软件测试

    我们先说一下软件测试。软件测试,顾名思义,对软件进行测试,我们在什么?财务也要软件测试?文章中提到过软件测试的执行...

  • 软件测试(功能、接口、性能、自动化)详解

    一、软件测试功能测试 测试用例编写是软件测试的基本技能;也有很多人认为测试用例是软件测试的核心;软件测试中最重要的...

网友评论

      本文标题:软件测试实验报告一

      本文链接:https://www.haomeiwen.com/subject/qeqaqftx.html