junit白盒测试Java.docx

上传人:b****7 文档编号:11044424 上传时间:2023-02-24 格式:DOCX 页数:8 大小:64.04KB
下载 相关 举报
junit白盒测试Java.docx_第1页
第1页 / 共8页
junit白盒测试Java.docx_第2页
第2页 / 共8页
junit白盒测试Java.docx_第3页
第3页 / 共8页
junit白盒测试Java.docx_第4页
第4页 / 共8页
junit白盒测试Java.docx_第5页
第5页 / 共8页
点击查看更多>>
下载资源
资源描述

junit白盒测试Java.docx

《junit白盒测试Java.docx》由会员分享,可在线阅读,更多相关《junit白盒测试Java.docx(8页珍藏版)》请在冰豆网上搜索。

junit白盒测试Java.docx

junit白盒测试Java

 

计算机科学与技术系

实验报告

 

专业名称软件工程

课程名称软件测试

项目名称白盒测试之赋税管理系统

班级12级软件工程

学号1204091034

姓名常成

同组人员

实验日期2014/10/13

 

一、实验内容:

利用白盒测试之赋税管理系统练习基本路径测试方法。

二、实验目的与要求:

实验目的:

基本路径测试方法练习

收入Income和供养人数nDependance来计算赋税金额的程序。

程序输入是Income和nDependance,程序输出是:

总税金TaxTotal

应缴所得税计算公式:

TaxSubtotal

收入(income)

税率计算公式

<10000

0.02*income

10000≤income<50000

200+0.03*(income-10000)

≥50000

1400+0.04*(income-50000)

免税部分:

exemption=人数*50;

实缴所得税:

TaxTotal=TaxSubtotal–exemption

实验要求:

使用java语言实现。

画出该程序的控制流图

计算圈复杂度

获取基本路径

设计测试用例,使得每条基本路径都要覆盖到。

三、实验步骤

1、算法实现(附上源代码)

程序Java代码:

packageP.test;

importjava.util.Scanner;

publicclassTexTotal{

privatedoubletotals;

privatedoubleincome;

privateintper;

publicdoublegettotals(){

returntotals;

}

publicvoidsetShuru(doubleincome,intper){

this.income=income;

this.per=per;

}

publicbooleangetShuru(){

try{

Scannerin=newScanner(System.in);

System.out.println("请输入你的工资和家庭人数(以空格隔开):

");

this.income=in.nextInt();

this.per=in.nextInt();

}catch(Exceptione){

System.out.println("请输入正确的工资数目!

");

System.out.println("错误类型:

"+e);

returnfalse;

}

returntrue;

}

publicvoidIncome(){

if(this.income<=0||this.per<=0){

System.out.println("请输入正确的家庭人数和收入!

");

}elseif(this.income<10000){

this.totals=this.income*0.02-this.per*50;

}elseif(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;

}

}

publicvoidPrints(){

System.out.println("需要缴纳的税为:

"+this.totals);

}

publicstaticvoidmain(Stringargs[]){

TexTotald=newTexTotal();

if(d.getShuru()){

d.Income();

d.Prints();

}

}

}

测试代码:

packageP.test;

importstaticorg.junit.Assert.*;

importjunit.framework.Assert;

importorg.junit.After;

importorg.junit.Before;

importorg.junit.Test;

publicclassTexTotalTest{

TexTotals=newTexTotal();

@Before

publicvoidsetUp()throwsException{

}

@After

publicvoidtearDown()throwsException{

}

@Test

publicvoidtestGetShuru1(){

s.setShuru(9994,5);

s.Income();

Assert.assertEquals(0.0,s.gettotals());

}

@Test

publicvoidtestGetShuru2(){

s.setShuru(10023,3);

s.Income();

Assert.assertEquals(50.69,s.gettotals());

}

@Test

publicvoidtestGetShuru3(){

s.setShuru(59232,4);

s.Income();

Assert.assertEquals(1569.28,s.gettotals());

}

@Test

publicvoidtestGetShuru4(){

s.setShuru(500,0);

s.Income();

Assert.assertEquals(0.0,s.gettotals());

}

@Test

publicvoidtestGetShuru5(){

s.setShuru(-50000,4);

s.Income();

Assert.assertEquals(0.0,s.gettotals());

}

}

2、控制流图

 

3、测试用例设计

编号

输入数据

预期输出

1

供养人数5收入9994

总税金0.0

2

供养人数3收入10023

总税金50.69

3

供养人数4收入59232

总税金1569.28

4

供养人数0收入500

总税金0.0

请输入正确的家庭人数和收入!

5

供养人数4收入-50000

总税金0.0

请输入正确的家庭人数和收入!

3测试数据与实验结果分析

测试均顺利通过。

路径覆盖率为100%。

四、实验小结:

(实验过程中的问题分析、产生的原因以及解决方法;实验结果分析;有待优化思路)

通过本次试验对Java的使用有了进一步的认识,对控制流图更是有了进一步的认识,知道了怎么去画控制流图和路径测试用例的设计,更是对计算路径覆盖率有了进一步的认识,所以本次试验的收获还是很大的。

五、其它

 

得分(百分制)

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 历史学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1