码迷,mamicode.com
首页 > 其他好文 > 详细

第三次作业+105032014126

时间:2017-03-31 00:45:00      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:计算方法   void   分享   lsp   流程图   equal   漏洞   三次   log   

 

被测试代码的地址:http://www.cnblogs.com/leezoey/p/6530136.html

测试流程图:

根据代码的编译方式为:

技术分享

测试用例设计

测试函数

耳机数量

外壳数量

护膜数量

预期结果

实际结果

 

 

 

 

 

Charge

11

11

11

True

True

-1

11

11

False

False

11

-1

11

False

False

11

11

-1

False

False

Ex

11

11

False

报错

11

Ex

11

False

报错

11

11

Ex

False

报错

11ex

11

11

False

报错

11

11ex

11

False

报错

11

11

11ex

False

报错

 

commission

1

1

1

9.8

9.8

10

10

10

98.0

98.0

100

100

100

1820.0

0.0

根据这个所写的Junit测试代码:

@Before
public void setUp() throws Exception {
}

@SuppressWarnings({ "static-access"})
@Test
public void testCharge() {


assertEquals(true,monyCount.charge("11","11","11"));
assertEquals(false,monyCount.charge("-1","11","11"));
assertEquals(false,monyCount.charge("11","-1","11"));
assertEquals(false,monyCount.charge("11","11","-1"));
assertEquals(false,monyCount.charge("11ex","11","11"));
assertEquals(false,monyCount.charge("11","11ex","11"));
assertEquals(false,monyCount.charge("11","11","11ex"));
assertEquals(false,monyCount.charge("ex","11","11"));
assertEquals(false,monyCount.charge("11","ex","11"));
assertEquals(false,monyCount.charge("11","11","ex"));


}

 

@SuppressWarnings("static-access")
@Test
public void testCommission() {

assertEquals(9.8,monyCount.commission("1", "1", "1"),0.01);
assertEquals(98.0,monyCount.commission("10", "10", "10"),0.01);
assertEquals(1820.0,monyCount.commission("100", "100", "100"),0.01);




}

但是测试的结果进行到测试用例

assertEquals(false,monyCount.charge("11ex","11","11"));便报错,原因为这个方法是会因为输入的不合法(即数据为带字母或者符号)而中止报错

更改测试代码为

@Test
public void testCommission() {

assertEquals(9.8,monyCount.commission("1", "1", "1"),0.01);
assertEquals(98.0,monyCount.commission("10", "10", "10"),0.01);
assertEquals(1820.0,monyCount.commission("100", "100", "100"),0.01);


}

发现前两个测试还是可以进行,但是第3个结果与预期不符合

技术分享

修改建议:

建议添加对字母和符号的判断以及防崩溃的函数

总的数据计算方法有巨大漏洞,估计为方法上的if(money>=1800)这个判断条件变量写错导致total数据在大于1800的时候变为0

 

第三次作业+105032014126

标签:计算方法   void   分享   lsp   流程图   equal   漏洞   三次   log   

原文地址:http://www.cnblogs.com/HSing1225/p/6649118.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!