Software Testing, Lab 1

Software Testing, Lab 1

一.实验要求:

  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.

 

二.实验过程

1.JUnit、Hamcrest的安装:

从网上下载junit-4.12.jar 和 hamcrest-all-1.3.jar文件。

 

2.

1)在Eclipse中新建项目 (File - new - javaproject)

右键点击项目,选择Build Path - Configure Build Path

然后点击Libraries - Add External JARs,选择jar包打开,确认

 

2)Eclemma的安装:

在菜单栏选择Help - Eclipse Marketplace,搜索Eclemma,点击Install安装,重启Eclipse

 

 

 

3.代码编写

1)triangle.java

package hw;

 

public class triangle {

 

    public static void main(String[] args) {

       // TODO Auto-generated method stub

 

    }

   

    public int tri(int a,int b,int c){

       int m=0;

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

           if(a==b&&b==c) m=1;  //equilateral

           else if(a==b||b==c||a==c) m=2;  //isosceles

           else m=3;  //scalene

       }

       else m=-1;

      

       return m;

    }

 

}

 

2)triangleTest.java

package hw;

 

import static org.junit.Assert.*;

 

import org.junit.Test;

 

public class triangleTest {

   

    triangle t = new triangle();

   

    @Test

    public void test() {

       int f = t.tri(1,1,1);

       assertEquals( 1 , f );

       f = t.tri(2,2,3);

       assertEquals( 2 , f );

       f = t.tri(2,3,4);

       assertEquals( 3 , f );

       f = t.tri(1,1,4);

       assertEquals( -1 , f );

    }

 

}

 

 

三.实验结果

各种情况的测试用例各一个,测试结果均通过

 

equilateral triangle返回1, isosceles triangle返回2,scalene triangle返回3,不能构成三角形则返回-1

 

测试结果如图

 

转载于:https://www.cnblogs.com/zhaogang3015207537/p/8647656.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值