资源描述:
《软件质量保证与测试——静态白盒测试》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验分数占百分比得分实验室演示10%实验报告90%合计100%软件质量保证与测试2015年春季教师:杨秋辉实验报告1–静态白盒测试学号:姓名:1引言白盒测试(white-boxtesting)又称透明盒测试(glassboxtesting)、结构测试(structuraltesting)等,软件测试的主要方法之一,也称结构测试、逻辑驱动测试或基于程序本身的测试。测试应用程序的内部结构或运作,而不是测试应用程序的功能(即黑盒测试)。在白盒测试时,以编程语言的角度来设计测试案例。测试者输入数据验证数据流在程序中的流动路径,并确定适当的输出,类似测试电路中的节点。测试者了解待测试程序的
2、内部结构、算法等信息,这是从程序设计者的角度对程序进行的测试。FindBugs是由BillPugh和DavidHovemeyer创建的开源程序,用来查找Java代码中的程序错误。它使用静态分析来识别Java程序中上百种不同类型的潜在错误。潜在错误可分为四个等级:恐怖的(scariest)、吓人的(scary)、令人困扰的(troubling)和值得关注的(ofconcern),这是根据其可能产生的影响或严重程度,而对开发者的提示。2测试结果记录表1FindBugs静态测试结果分析表编号源代码(指明是哪个函数中的哪几条语句)编译提示静态测试结果你的修改再次静态测试结果你的理解1函数
3、function1():if(str!=null)无错误Bug:Repeatedconditionaltestintest.function1()Thecodecontainsaconditionaltestisperformedtwice,onerightaftertheother(e.g.,x==0
4、
5、x==0).Perhapsthesecond删除第2个if(str!=null)无错误是缺陷,需要根据程序实际应该的逻辑来确定是否修复。6occurrenceisintendedtobesomethingelse(e.g.,x==0
6、
7、y==0).如静态测试结果所述,两个相同的
8、条件语句重复出现,没有实际意义。如果只是程序员无意中多写了一次,不会影响程序运行结果;但按照代码编写的一般规律,这里应该是两个不同的判定条件。2函数function3():Stringstr3=String.format("{0}{1}",str1,str2);无错误Bug:String.format(String,Object[])needsprintf-styleformatbutcalledwithMessageFormatAmethodiscalledthatexpectsaJavaprintfformatstringandalistofarguments.However
9、,theformatstringdoesn'tcontainanyformatspecifiers(e.g.,%s)butdoescontainmessageformatelements(e.g.,{0}).ItislikelythatthecodeissupplyingaMessageFormatstringwhenaprintf-styleformatstringisrequired.Atruntime,alloftheargumentswillbeignoredandtheformatstringwillbereturnedexactlyasprovidedwithouta
10、nyformatting.修改为Stringstr3=String.format("%s%s",str1,str2);无错误是缺陷,函数调用时参数使用错误。String.format(String,Object[])前面的String部分需要像printf一样使用%s占位符才能显示后面的变量。3函数function5():returnnewRandom(seed).nextInt();无错误Bug:RandomobjectcreatedandusedonlyonceinTest.function5(int)Thiscodecreatesajava.util.Randomobjec
11、t,usesittogenerateonerandomnumber,andthendiscardstheRandomobject.Thisproducesmediocrequalityrandomnumbersandisinefficient.Ifpossible,rewritethecodesothattheRandomobjectiscreatedonceandsaved,andeachtimeanewrandomnumberisrequiredinvokeamethodon