软件测试实验二

  • 格式:doc
  • 大小:59.79 KB
  • 文档页数:7

计算机科学与技术系
实 验 报 告

专业名称 软件工程
课程名称 软件测试
项目名称 赋税管理系统的实现与测试
班 级
学 号
姓 名
同组人员
实验日期
一、实验内容:
某程序是按收入(Income)和供养人数(nDependance)来计算赋税金额。它
的输入是:Income和nDependance,它的输出是总税金(TaxTotal)。
应缴所得税计算公式:TaxSubtotal

收入(income) 税率计算公式(TaxSubtotal)
<10000 0.02*income
10000income<50000
200+0.03*(income-10000)
50000
1400+0.04*(income-50000)

免税部分:exemption = 人数*50;
应缴所得税: TaxTotal = TaxSubtotal – exemption

二、实验目的与要求:

实验目的:基于上述规格描述,设计并实现该程序,使用基本路径测试方法,完
成该程序的充分测试。

实验要求:
1、使用java语言实现
2、画出该程序的控制流图
3、计算圈复杂度,获得基本路径数目
4、计算该程序的所有基本路径
5、为每条基本路径设计测试用例
6、使用Junit框架,执行测试,并对测试结果进行分析。

三、实验步骤
1、 算法实现(附上源代码)

代码:
package Project.com.cn.test;

import java.util.Scanner;
public class TexTotal {
private double totals;
private double income;
private int per;
public double gettotals(){
return totals;
}
public void setShuru(double income,int per){
this.income=income;
this.per=per;
}
public boolean getShuru() {
try {
Scanner in = new Scanner(System.in);
System.out.println("请输入你的工资和家庭人数(以空格隔开):");
this.income = in.nextInt();
this.per = in.nextInt();
} catch (Exception e) {
System.out.println("请输入正确的工资数目!");
System.out.println("错误类型:" + e);
return false;
}
return true;
}
public void Income(){
if(this.income<=0||this.per<=0){
System.out.println("请输入正确的家庭人数和收入!");
}else if(this.income < 10000){
this.totals=this.income*0.02-this.per*50;
}else if(this.income>=10000 && this.income<50000){
this.totals=200+(this.income-10000)*0.03-this.per*50;
}else{
this.totals=1400+(this.income-50000)*0.04-this.per*50;
}
if(this.totals<0){
this.totals=0;
}
}
public void Prints() {
System.out.println("需要缴纳的税为:"+this.totals);
}
public static void main(String args[]){
TexTotal d=new TexTotal();
if(d.getShuru()){
d.Income();
d.Prints();
}
}

}

测试代码:
package Project.com.cn.test;

import static org.junit.Assert.*;
import junit.framework.Assert;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class TexTotalTest {
TexTotal s=new TexTotal();

@Before
public void setUp() throws Exception {
}

@After
public void tearDown() throws Exception {
}

@Test
public void testGetShuru1() {
s.setShuru(9999,5);
s.Income();
Assert.assertEquals(0.0,s.gettotals());
}
@Test
public void testGetShuru2() {
s.setShuru(10025,3);
s.Income();
Assert.assertEquals(50.75,s.gettotals());
}
@Test
public void testGetShuru3() {
s.setShuru(60000,4);
s.Income();
Assert.assertEquals(1600,s.gettotals());
}
@Test
public void testGetShuru4() {
s.setShuru(30,0);
s.Income();
Assert.assertEquals(0.0,s.gettotals());
}
@Test
public void testGetShuru5() {
s.setShuru(-30,4);
s.Income();
Assert.assertEquals(0.0,s.gettotals());
}
}

2、控制流图

1、
2

30
31
4

6
5

7
8

9
11、
12

3
3、 测试用例设计
编号 输入数据 预期输出
1 供养人数5收入9999 总税金0.0
2 供养人数3收入10025 总税金50.75
3 供养人数4收入60000 总税金1600
4 供养人数0收入30 总税金0.0
请输入正确的家庭人
数和收入!
5 供养人数4收入-30 总税金0.0
请输入正确的家庭人
数和收入!
3 测试数据与实验结果分析
测试均顺利通过。路径覆盖率为100%。
四、实验小结:
(实验过程中的问题分析、产生的原因以及解决方法;实验结果分析; 有
待优化思路)

通过本次试验对控制流图有了进一步的认识,知道了怎么去画控

制流图和路径测试用例的设计,更是对计算路径覆盖率有了进一步的

16
40
41

42
认识。
五、其它

得分(百分制)