实验关于Junit和Eclemma

Lab关于Junit和Eclemma


下载和安装

  1. Junit和Hamcrest可以去junit的github下载点击这里,然后在需要添加的项目右键built path->configure built path ->add external jars,添加下载好的Junit和Hamcrest的jar包即可。
  2. Eclemma安装,通过远程地址安装和下载zip解压到eclipse的安装文件夹dropins文件夹里面,具体参考这里

测试设计

  1. 编写三角形问题,注意输入3条边的长度需要满足三角形定义,才能进行下一步判断和输入的必选是整数值,否则抛出异常

    package st;
    public class triangle {
    private boolean caculate(int a, int b, int c) {
    	if(a+b>=c && a-b<=c)
    		return true;
    	else 
    		return false;
    }
    public Boolean isTriangle(int a, int b, int c) {
    	boolean result = true;
    	result = caculate(a, b, c);
    	result = caculate(a, c, b);
    	result = caculate(c, b, a);
    	return result;
    }
    public boolean isEquilateral(int a, int b, int c) {
    	if(isTriangle(a, b, c) == false) return false;
    	if(a == b && b == c)
    		return true;
    	else
    		return false;
    }

    public boolean isIsosceles(int a, int b, int c) { if(isTriangle(a, b, c) == false) return false; if(a == b || b == c || a == c) return true; else return false; }

    public boolean isScalene(int a, int b, int c) { if(!isEquilateral(a, b, c)&& !isIsosceles(a, b, c)) return true; else return false; } }

  2. 设计测试环节,可以右键new->junit test case自动生成,或者自己在建立一个文件夹然后新建立一个包包名和测试的类一致

    package st;
    import static org.junit.Assert.*;
    import org.junit.Before;
    import org.junit.Ignore;
    import org.junit.Test;
    public class JuintTest {
    private static triangle testTriangle = new triangle();
    @Before //每次运行test都会执行该方法
    public void setUp()throws Exception{

    } @Test //测试案例 public void testIsEquilateral(){ assertEquals(true, testTriangle.isEquilateral(5, 5, 5)); } @Test public void testIsIsosceles(){ assertEquals(true, testTriangle.isIsosceles(5, 5, 5)); } @Test public void testIsScalene(){ assertEquals(true, testTriangle.isScalene(4, 5, 6)); } } 测试结果

  3. 覆盖,当安装Eclemma后会在工具栏出现一个新的运行方式按钮,点击就可以查看覆盖效果。如下:

 

转载于:https://www.cnblogs.com/faith30/p/6535379.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值