文章目录
- 实验目的
- 实验环境
- 实验内容
- 安装Eclipse
- 测试代码
- 分析和总结
实验目的
理解和掌握使用 Eclemma 软件测试工具对 Java 语言编写的程序进行语句覆盖测试。
实验环境
装有 Eclipse 的计算机。
实验内容
安装Eclipse
下载地址
-
点击 Download Packages
-
根据操作系统和所需的软件点击相应的下载链接
-
可以根据网络环境更换镜像地址,我挂了梯子所以直接下载就可以
没有梯子的话,点击Show all 是会显示在国内大连东软信息学院的镜像
-
选择镜像地址之后就会进入这个捐赠界面,然后就会开始下载
如果没有开始下载,点击这里就可以开始下载
-
下载好压缩包后解压,注意路径中不能有中文
-
点击运行
-
选择项目默认的新建目录,然后点 Launch
-
点击 Help,选择 Install New Software
9. 点击 Add
粘贴这个网址到 Location ,Name 随便起一个名字,然后点Add
https://download.eclipse.org/technology/babel/update-site/latest/
如果有梯子的话,设置一下代理
等待一会,会出现语言包的下载选项,勾选简体中文的语言包然后点击 Next
继续Next
accept然后finish
下面就会出现安装的进度条
打勾后点击Trust
最后重启
官方的语言包做的不完整,所以软件打开后还会有很多地方是英文
测试代码
-
创建一个新项目Nextday,将源代码放到src下,然后点击“下一步”
点击“完成”
-
右键src,新建一个包,然后把代码放到包中
-
在包中写好测试代码
package net.mooctest;
import org.junit.Assert;
import org.junit.Test;
public class DemoTest {
@Test
public void test() {
Date date1 = new Date(12, 5, 2029);
Date date2 = new Date(12, 5, 2029);
Date date3 = new Date(12, 31, 2019);
Date date4 = new Date(2, 28, 2020);
Date date5 = new Date(3, 31, 2020);
Year year1 = new Year(2019);
Month month = new Month(1, year1);
Day day = new Day(1, month);
Nextday next = new Nextday();
// test date
Assert.assertTrue(date1.equals(date2));
Assert.assertFalse(date1.equals(date3));
Assert.assertFalse(date1.equals(year1));
System.out.println(Nextday.nextDay(date1));
Nextday.nextDay(date3);
Nextday.nextDay(date4);
Nextday.nextDay(date5);
date1.printDate();
Assert.assertFalse(month.equals(1));
Assert.assertFalse(day.equals(1));
try {
Date date6 = new Date(1, 1, 0);
} catch (IllegalArgumentException e) {
e.getMessage();
}
try {
Date date7 = new Date(1, 1, -1);
Assert.assertTrue(date7.getYear().increment());
} catch (Exception e) {
Assert.assertTrue(e instanceof IllegalArgumentException);
}
try {
Month month1 = new Month(0, year1);
Month month2 = new Month(1, year1);
Assert.assertFalse(month2.equals(date1));
Assert.assertFalse(month2.equals(month1));
} catch (Exception e) {
Assert.assertTrue(e instanceof IllegalArgumentException);
}
try {
Month month1 = new Month(1, year1);
Day day1 = new Day(-1, month1);
Assert.assertTrue(day1.equals(1));
} catch (Exception e) {
Assert.assertTrue(e instanceof IllegalArgumentException);
}
}
}
- 配置Coverage
配置好后点击“应用”,然后点击Coverage,在下方可以看到结果
分析和总结
- 在源码Year.java中,第十行应该是“Not a valid year”而不是“Not a valid month”
- 源码中应该包含注释,没有任何注释不符合规范