




免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验分数占百分比得分实验室演示10%实验报告90%合计100%软件质量保证与测试2015年春季教师:杨秋辉实验报告1 静态白盒测试学号: 姓名: 1 引言白盒测试(white-box testing)又称透明盒测试(glass box testing)、结构测试(structural testing)等,软件测试的主要方法之一,也称结构测试、逻辑驱动测试或基于程序本身的测试。测试应用程序的内部结构或运作,而不是测试应用程序的功能(即黑盒测试)。在白盒测试时,以编程语言的角度来设计测试案例。测试者输入数据验证数据流在程序中的流动路径,并确定适当的输出,类似测试电路中的节点。测试者了解待测试程序的内部结构、算法等信息,这是从程序设计者的角度对程序进行的测试。FindBugs是由Bill Pugh和David Hovemeyer创建的开源程序,用来查找Java代码中的程序错误。它使用静态分析来识别Java程序中上百种不同类型的潜在错误。潜在错误可分为四个等级:恐怖的(scariest)、吓人的(scary)、令人困扰的(troubling)和值得关注的(of concern),这是根据其可能产生的影响或严重程度,而对开发者的提示。2 测试结果记录表1 FindBugs静态测试结果分析表编号源代码(指明是哪个函数中的哪几条语句)编译提示静态测试结果你的修改再次静态测试结果你的理解1函数function1():if(str!=null) 无错误Bug: 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 occurrence is intended to be something else (e.g., x = 0 | y = 0).删除第2个if(str!=null)无错误是缺陷,需要根据程序实际应该的逻辑来确定是否修复。如静态测试结果所述,两个相同的条件语句重复出现,没有实际意义。如果只是程序员无意中多写了一次,不会影响程序运行结果;但按照代码编写的一般规律,这里应该是两个不同的判定条件。2函数function3():String str3 = String.format(01, str1, str2);无错误Bug: String.format(String, Object) 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 is 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(String, Object)前面的String部分需要像printf一样使用%s占位符才能显示后面的变量。3函数function5():return new Random(seed).nextInt();无错误Bug: 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 object. 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 object 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 java.security.SecureRandom instead (and avoid allocating a new SecureRandom for each random number needed). 修改为Random ran = new Random(seed);return ran.nextInt();无错误是缺陷。Random出来的对象没保存,而是直接调用它的另一方法,这样做Random的效率很低,应该把它保存下来,下次再用到不用new,提高效率。4函数function7():synchronized (str)无错误Bug: Synchronization on interned String in Test.function7()The code synchronizes on interned String.private static String LOCK = LOCK;. synchronized(LOCK) .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 /java/forums/t96352.html and /browse/JETTY-352. See CERT CON08-J. Do not synchronize on objects that may be reused for more information.删除synchronized (str)和后面无错误是缺陷。对String类型上锁可能造成其它运行在java虚拟机上的类的String上锁,导致大面积死锁。3 遗漏缺陷分析【列出你认为静态测试应该可以发现、但被遗漏的缺陷】表2 FingBugs静态测试遗漏缺陷表编号源代码缺陷描述你认为此缺陷为什么不能被自动工具发现?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.isNaN(m_dValue)无错误Nan很特殊(表示未定义和不可表示的值),没有任何值跟它相等,包括它自身,所以x=Double.NaN永远返回false。5 自动化测试和手动测试的比较1. 效率方面,自动化测试明显优于手动测试2. 准确率方面,虽然自动化测试效率较高,但其找出的“错误”可能不是错误,准确率赶不上手动测试。3. 资源耗费方面,自动测试明显优于人工。6 静态测试和动态测试的比较区别一:静态测试是用于预防的,动态测试是用于矫正的区别二:多次的静态测试比动态测试要效率和效益高区别三:静态测试综合测试程序代码区别四:在相当短的时间里,静态测试的覆盖度能达到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”静态测试能够发现而动
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 课件模板色彩搭配图表
- 生态谷物教程课件
- 贫血患者诊疗与健康教育
- 高处跌落应急培训
- 星级酒店管理培训
- 小学石头画课件
- 课件显示重新插入磁盘
- 历史考试题及答案大全
- 课件显示屏文字竖向显示
- 快门高压考试题及答案
- 2025年大麻酚油(CBD油)行业研究报告及未来行业发展趋势预测
- 行政执法常识考试题库及答案
- 山东省潍坊市2025-2026学年上学期高三开学调研监测语文试题参考答案
- 钢结构隔断施工方案(3篇)
- GB/T 20716.2-2025道路车辆牵引车和挂车之间的电连接器(7芯)第2部分:12 V标称电压车辆的制动系统和行走系的连接
- 学校“1530”安全教育记录表(2024年秋季全学期)
- 公路工程标准施工招标文件(2018年版)
- SJG 01-2010 深圳市地基基础勘察设计规范-高清现行
- 康复护理学-康复评定认知功能评定
- 最全的食物相克表(打印版)
- 施工现场安全标志和安全防护设施设置方案
评论
0/150
提交评论