软件测试 第一次实验

Tasks:

1.     Install Junit(4.12),Hamcrest(1.3) with Eclipse

2.     Install Eclemmawith Eclipse

3.     Write a javaprogram for the triangle problem and test the program with Junit.

a)       Description oftriangle problem:

Functiontriangle takes three integers a,b,cwhich are length of triangle sides; calculates whether the triangle isequilateral, isosceles, or scalene.

Requirements for theexperiment:

1.     Finish the tasksabove individually.

2.     Check in yourjava code and junit test program to github and send the URL to tjuscsst@qq.com

3.     Post yourexperiment report to your blog and send the URL to tjuscsst@qq.com , the following information should beincluded in your report:

a)       The brief descriptionthat you install junit, hamcrest and eclemma.

b)      The test resultand coverage report (print screen) of your tests on triangle problem. 


一、使用eclips,配置Junit4.12,hamcrest-all-1.3

下载这两个jar包,在src文件目录下新建文件夹lib,将两个jar包复制进去。打开eclips项目,右键分别点击两个jar包,选择build path.

二、安装Eclemmawith插件

下载Eclemmawith-2.3.3,在eclipse中Help-中选择install new software,选择压缩包即可安装成功,重新启动eclipse,会出现最左面的图标


三、编写Triangle()函数

package lab1.tr;

public class Triangle {
	public String triangle(int a,int b,int c)
	{
		if(a==b && b==c)
			return "Equilateral triangle";
		else if(a==b || b==c || a==c)
			return "Isosceles triangle";
		else if(a+b<c || a+c<b || b+c<a)
			return "Not triangle";
		return "Scalene triangle";
	}
}
四、新建测试类TestTriangle.java,编写Junit代码

先逐一测试了各个输出。

最后使用了Parameter的参数化测试,将所有测试用例放到了一起。

package lab1.tr;

import static org.junit.Assert.*;

import java.util.Collection;
import java.util.Arrays;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

@RunWith(Parameterized.class)
public class TestTriangle {
	private Triangle tri;
	
	private int a,b,c;
	private String s;
	
	public TestTriangle(int a,int b,int c,String s){
		this.a=a;
		this.b=b;
		this.c=c;
		this.s=s;
	}
	
	
	@Before
	public void setup(){
		tri=new Triangle();
	}
	
	@Test
	public void testEquilateral(){
		assertEquals("Equilateral triangle",tri.triangle(3,3,3));
	}
	@Test
	public void testIsosceles(){
		assertEquals("Isosceles triangle",tri.triangle(3,3,4));
	}
	@Test
	public void testScalene(){
		assertEquals("Scalene triangle",tri.triangle(3,4,5));
	}
	@Test
	public void testNotTriangle(){
		assertEquals("Not triangle",tri.triangle(3, 4, 8));
	}
	
	//参数化测试
	@Parameters
	public static Collection<Object[]> getResult(){
		return Arrays.asList(new Object[][]{
			{3,3,3,"Equilateral triangle"},
			{3,3,4,"Isosceles triangle"},
			{3,4,5,"Scalene triangle"},
			{3,4,8,"Not triangle"}
		});
	}
	
	@Test
	public void testTriangle(){
		assertEquals(this.s,tri.triangle(a, b, c));
	}


}

五、覆盖结果




### 南京邮电大学汇编语言第一次实验 #### 实验目的 通过本次实验,学生能够掌握基本的汇编语言语法结构以及如何利用集成开发环境(IDE)编写简单的汇编程序。此外,在初次接触单片机系统的背景下,了解其内部工作原理并熟悉调试工具的应用。 #### 实验内容概述 首次实验主要集中在基础概念的学习与实践操作上。具体来说: - **安装配置Keil IDE**:确保每位同学都能顺利打开软件,并完成必要的设置以便后续项目创建和代码编辑[^2]。 - **简单指令集练习**:编写一段用于验证数据传输功能的小型程序,比如实现两个寄存器之间数值交换的操作;这有助于加深对CPU执行过程的理解[^1]。 ```assembly ; Example of swapping two registers in assembly language MOV A, R0 ; Move value from register R0 to accumulator A XCHG A, R1 ; Exchange values between accumulator and another register (R1 here) MOV R0, A ; Store the exchanged result back into original source location ``` - **初步认识存储空间布局**:通过对特定地址范围内的读写测试来探索不同类型的内存区域及其访问方式,如RAM、ROM等特性差异。 #### 报告撰写指南 一份完整的实验报告应当包含以下几个部分: - 封面页注明个人信息及课题名称; - 正文开头简述此次学习目标和个人收获感言; - 中间主体段落详细介绍所做工作的具体内容,包括但不限于遇到的问题解决方案描述; - 结尾处总结整个过程中学到的知识要点,并对未来可能继续深入研究的方向给出建议。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值