软件质量保证与测试——静态白盒测试

上传人:woxinch****an2018 文档编号:39301533 上传时间:2018-05-14 格式:DOC 页数:6 大小:71KB
返回 下载 相关 举报
软件质量保证与测试——静态白盒测试_第1页
第1页 / 共6页
软件质量保证与测试——静态白盒测试_第2页
第2页 / 共6页
软件质量保证与测试——静态白盒测试_第3页
第3页 / 共6页
软件质量保证与测试——静态白盒测试_第4页
第4页 / 共6页
软件质量保证与测试——静态白盒测试_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《软件质量保证与测试——静态白盒测试》由会员分享,可在线阅读,更多相关《软件质量保证与测试——静态白盒测试(6页珍藏版)》请在金锄头文库上搜索。

1、1软件质量保证与测试软件质量保证与测试 2015 年春季年春季 教师:杨秋辉 实验报告实验报告 1 静态白盒测试静态白盒测试学号: 姓名:1 引言引言白盒测试(white-box testing)又称透明盒测试(glass box testing)、结构测试(structural testing)等,软件测试的主要方法之一,也称结构测试、逻辑驱动测试 或基于程序本身的测试。测试应用程序的内部结构或运作,而不是测试应用程序的功能(即黑盒测试)。在白盒测试时,以编程语言的角度来设计测试案例。测试者 输入数据验证数据流在程序中的流动路径,并确定适当的输出,类似测试电路中的节点。测试者了解待测试程序的

2、内部结构、算法等信息,这是从程序设计者的角度 对程序进行的测试。FindBugs 是由 Bill Pugh 和 David Hovemeyer 创建的开源程序,用来查找 Java 代码中的程序错误。它使用静态分析来识别 Java 程序中上百种不同类型的潜在错误。 潜在错误可分为四个等级:恐怖的(scariest)、吓人的(scary)、令人困扰的(troubling)和值得关注的(of concern),这是根据其可能产生的影响或严重程度, 而对开发者的提示。2 测试结果记录测试结果记录表 1 FindBugs 静态测试结果分析表编 号源代码(指明是哪个函 数中的哪几条语句)编 译 提 示静态

3、测试结果你的修改再 次 静 态 测 试 结 果你的理解1函数function1():if(str!=null) 无 错 误BugBug: Repeated conditional test in test.function1()The code contains a conditional test is performed twice, one right after the other (e.g., x = 0 | x = 0). Perhaps the second 删除第2个if(str!=null)无 错 误是缺陷,需要根据程序 实际应该的逻辑来确定 是否修复。如静态测试结果所述,

4、两个相同的条件语句重 复出现,没有实际意义。实验分数实验分数占百分比占百分比得分得分实验室演示实验室演示10%实验报告实验报告90%合计合计100%2occurrence is intended to be something else (e.g., x = 0 | y = 0).如果只是程序员无意中 多写了一次,不会影响 程序运行结果;但按照 代码编写的一般规律, 这里应该是两个不同的 判定条件。2函数function3():String str3 = String.format(“01“, str1, str2);无 错 误BugBug: String.format(String, Obj

5、ect) needs printf-style format but called with MessageFormatA method is called that expects a Java printf format string and a list of arguments. However, the format string doesnt contain any format specifiers (e.g., %s) but does contain message format elements (e.g., 0). It is likely that the code i

6、s supplying a MessageFormat string when a printf-style format string is required. At runtime, all of the arguments will be ignored and the format string will be returned exactly as provided without any formatting. 修改为String str3 = String.format(“%s%s“, str1, str2);无 错 误是缺陷,函数调用时参 数使用错误。String.format

7、(String, Object)前面的String部 分需要像printf一样使用% s占位符才能显示后面的 变量。3函数function5():return new Random(seed).nextInt();无 错 误BugBug: Random object created and used only once in Test.function5(int)This code creates a java.util.Random object, uses it to generate one random number, and then discards the Random obje

8、ct. This produces mediocre quality random numbers and is inefficient. If possible, rewrite the code so that the Random object is created once and saved, and each time a new random number is required invoke a method on the existing Random 修改为Random ran = new Random(seed); return ran.nextInt();无 错 误是缺

9、陷。Random出来的 对象没保存,而是直接 调用它的另一方法,这 样做Random的效率很低, 应该把它保存下来,下 次再用到不用new,提 高效率。3object to obtain it. If it is important that the generated Random numbers not be guessable, you must not create a new Random for each random number; the values are too easily guessable. You should strongly consider using a

10、java.security.SecureRandom instead (and avoid allocating a new SecureRandom for each random number needed). 4函数function7():synchronized (str)无 错 误Bug: Synchronization on interned String in Test.function7()The code synchronizes on interned String.private static String LOCK = “LOCK“; .synchronized(LOC

11、K) . .Constant Strings are interned and shared across all other classes loaded by the JVM. Thus, this could is locking on something that other code might also be locking. This could result in very strange and hard to diagnose blocking and deadlock behavior. See http:/www.javalobby.org/java/forums/t9

12、6352.html and http:/jira.codehaus.org/browse/JETTY-352. See CERT CON08-J. Do not synchronize on objects that may be reused for more information.删除synchronized (str)和后面无 错 误是缺陷。对String类型上 锁可能造成其它运行在 java虚拟机上的类的 String上锁,导致大面积 死锁。43 遗漏缺陷分析遗漏缺陷分析【列出你认为静态测试应该可以发现、但被遗漏的缺陷】表 2 FingBugs 静态测试遗漏缺陷表编号源代码缺陷描述你

13、认为此缺陷为什么不能被自动工具发现?1函数function2():System.out.println(str);一句代码后,分号多一个不影响程序的性能和结果2函数function4():System.out.println(str.toString();Str本来就是String类型,又使用toString函 数转化并不存在潜在风险3函数function6():for(int i = 0;i 1 无错 误Min+max可能超过int最大值,得到负 数3If(m_dValue = Double.NaN)无 错Bug: Doomed test for equality to NaNDouble.

14、isNaN(m_dValue)无错 误Nan很特殊(表示未定义和不可表示的 值),没有任何值跟它相等,包括它自 身,所以x = Double.NaN永远返回5误false。5 自动化测试和手动测试的比较自动化测试和手动测试的比较1.效率方面,自动化测试明显优于手动测试2.准确率方面,虽然自动化测试效率较高,但其找出的“错误”可能不是错误,准确率赶不上手动测试。3.资源耗费方面,自动测试明显优于人工。6 静态测试和动态测试的比较静态测试和动态测试的比较区别一:静态测试是用于预防的,动态测试是用于矫正的区别二:多次的静态测试比动态测试要效率和效益高区别三:静态测试综合测试程序代码区别四:在相当短的

15、时间里,静态测试的覆盖度能达到 100%,而动态测试经常是只能达到 50%左右,原因动态测试发现的 bug 大部分只是在测试实际执行的那部分 代码区别五:动态测试比静态测试更花时间区别六:静态测试比动态测试更能发现 bug区别七:静态测试的执行可以在程序编码编译前,动态测试只能在编译后才能执行区别八:静态测试能发现动态测试所不能发现的一些:“Syntax error,code that hard to maintain,code that hard to test,code that does not confirm to coding standard, and ANSI violations”静态测试能够发现而动态测试不能发现的:程序逻辑错误等动态测试能够发现而静态测试不能发现的:内存的越界访问、环境错误等7 测试时遇到的困难和挑战测试时遇到的困难和挑战结果都是英文,不是那么易懂,需要查询资料。8 本实验的收获和结论本实验的收获和结论代码静态测试的重要性,静态测试能找到大部分错误,软件静态测试在软件开发过程中必不可少。69 意见和建议意见和建议当然有用,没知道怎么做试验。能根据指导完成实验。时间挺充足。希望减少需要自己填写的内容,个人觉得做的时候都是去各大搜索引擎找,实际学到都是在自己 不断编码过程中掌握的。

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号