Software-testing-foundations-lab1

Tasks:

  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. 

Ans:

1.新版的Mac版eclipse下载的package里自带了Junit,右键单击项目文件选择bulid path->add library->Junit5即可导入;从hamcrest官网下载了hamcrest-all-1.3,还是右键单击项目文件选择properties,选择java bulid path,add external jars导入.

2.点击help菜单,选择eclipse marketplace,搜索eclemma并下载安装即可.

3.写triangle程序

package cn.tju.scs; 

public class Triangle {

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

if(a==b && b==c)return 2;

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

if(a==b || b==c || a==c)return 3;

return 1;

}

return 0;

}

}

4.右键test文件夹下相同包名的包,new一个junit test case得到测试类,实现测试类

package cn.tju.scs;

import static org.junit.Assert.assertEquals;

import org.junit.jupiter.api.Test;

class TriangleTest {

@Test

void testTriangle() {

assertEquals(1, new Triangle().triangle(4, 3, 5));

}

@Test

void testTri() {

assertEquals(2,new Triangle().triangle(3,3,3));

}

@Test

void testT() {

assertEquals(0,new Triangle().triangle(1,1,3));

}

@Test

void testTT() {

assertEquals(3,new Triangle().triangle(3,3,1));

}

}

5.使用junit测试,右键run as junit test

6.使用eclemma测试覆盖率,右键coverage as junit test

转载于:https://www.cnblogs.com/sukebei/p/8641462.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值