Junit与Eclemma的安装及应用

发表于:2017-4-06 11:17

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:梦碎    来源:博客园

  一、junit和hamcrest安装及引入
  1.输入网址http://junit.org/junit4/下载junit及hamcrest
  2.打开Eclipse新建一个project
  3.右键点击build path 引进junit
  二、eclemma安装
  点击help-->Eclipse Marketplace-->在find中输入eclemma-->install-->重启Eclipse
  三、三角形问题及junit、hamcrest、eclemma的使用
  1、编写三角形判断程序
public class triangle_problem {
String triangle_juidje(double a,double b, double c){
if(a == b && a == c){
String str = new String();
str = "the trangle is equilateral";
return str;
}
if((a+b)>c &&(a+c)>b &&(b+c)>a){
if((a == b && a != c)|| (a==c && a != b) || (b == c && b != a)){
String str = new String();
str = "the trangle is isosceles";
return str;
}
if(a!=b && b!=c){
String str = new String();
str = "the trangle is scalene";
return str;
}
}
else{
String str = new String();
str = "the three edges can't make up a trangle!";
return str;
}
return null;
}
}
  2、junit类生成
  选中类-->new-->jUnit Test Case
  3、编辑junit内容
import static org.junit.Assert.*;
import org.junit.Test;
public class triangle_problemTest {
private triangle_problem tri;
@Test
public void testequilateral() {
tri = new triangle_problem();
assertEquals("the trangle is equilateral",tri.triangle_juidje(3,3,3));
}
@Test
public void testisosceles() {
tri = new triangle_problem();
assertEquals("the trangle is isosceles",tri.triangle_juidje(2,3,2));
}
@Test
public void testscalene() {
tri = new triangle_problem();
assertEquals("the trangle is scalene",tri.triangle_juidje(2,3,4));
}
@Test
public void testnottrangle() {
tri = new triangle_problem();
assertEquals("the three edges can't make up a trangle!",tri.triangle_juidje(2,3,5));
}
}
  4、运行junit文件
  5、运行eclemma
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号