ImageVerifierCode 换一换
格式:DOCX , 页数:22 ,大小:557.55KB ,
资源ID:3730431      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/3730431.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(白盒测试和黑盒测试实验报告.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

白盒测试和黑盒测试实验报告.docx

1、白盒测试和黑盒测试实验报告软件质量保证与测试实验指导计算机工程学院测试环境配置1. setting Junit(1) start EclipseSelect windows-preferences-java-build path class path variables(2) click new, the figure of new variable entry is shown.(3) name JUNIT_LIBselect file-选择JUnit 插件所对应的JAR文件所在地,在Eclipse的安装目录的plugins目录中2. JUNIT的组成框架其中,junit.framework

2、 和junit.runner是两个核心包。junit.framework 负责整个测试对象的框架junit.runner 负责测试驱动Junit的框架又可分为:A、被测试的对象。B、对测试目标进行测试的方法与过程集合,可称为测试用例(TestCase)。 C、测试用例的集合,可容纳多个测试用例(TestCase),将其称作测试包(TestSuite)。D、测试结果的描述与记录。(TestResult) 。E、每一个测试方法所发生的与预期不一致状况的描述,称其测试失败元素(TestFailure)F、JUnit Framework中的出错异常(AssertionFailedError)。JUni

3、t框架是一个典型的Composite模式:TestSuite可以容纳任何派生自Test的对象;当调用TestSuite对象的run()方法是,会遍历自己容纳的对象,逐个调用它们的run()方法。3. JUnit中常用的接口和类Test接口运行测试和收集测试结果Test接口使用了Composite设计模式,是单独测试用例(TestCase),聚合测试模式(TestSuite)及测试扩展(TestDecorator)的共同接口。 它的public int countTestCases()方法,它来统计这次测试有多少个TestCase,另外一个方法就是public voidrun( TestResu

4、lt ),TestResult是实例接受测试结果, run方法执行本次测试。 TestCase抽象类定义测试中固定方法TestCase是Test接口的抽象实现,(不能被实例化,只能被继承)其构造函数TestCase(string name)根据输入的测试名称name创建一个测试实例。由于每一个TestCase在创建时都要有一个名称,若某测试失败了,便可识别出是哪个测试失败。 TestCase类中包含的setUp()、tearDown()方法。setUp()方法集中初始化测试所需的所有变量和实例,并且在依次调用测试类中的每个测试方法之前再次执行setUp()方法。tearDown()方法则是在每

5、个测试方法之后,释放测试程序方法中引用的变量和实例。 开发人员编写测试用例时,只需继承TestCase,来完成run方法即可,然后JUnit获得测试用例,执行它的run方法,把测试结果记录在TestResult之中。 Assert静态类一系列断言方法的集合Assert包含了一组静态的测试方法,用于期望值和实际值比对是否正确,即测试失败,Assert类就会抛出一个AssertionFailedError异常,JUnit测试框架将这种错误归入Failes并加以记录,同时标志为未通过测试。如果该类方法中指定一个String类型的传参则该参数将被做为AssertionFailedError异常的标识信

6、息,告诉测试人员改异常的详细信息。JUnit 提供了6大类31组断言方法,包括基础断言、数字断言、字符断言、布尔断言、对象断言。 其中assertEquals(Object expcted,Object actual)内部逻辑判断使用equals()方法,这表明断言两个实例的内部哈希值是否相等时,最好使用该方法对相应类实例的值进行比较。而assertSame(Object expected,Object actual)内部逻辑判断使用了Java运算符“=”,这表明该断言判断两个实例是否来自于同一个引用(Reference),最好使用该方法对不同类的实例的值进行比对。asserEquals(St

7、ring message,String expected,String actual)该方法对两个字符串进行逻辑比对,如果不匹配则显示着两个字符串有差异的地方。ComparisonFailure类提供两个字符串的比对,不匹配则给出详细的差异字符。 TestSuite测试包类多个测试的组合TestSuite类负责组装多个Test Cases。待测得类中可能包括了对被测类的多个测试,而TestSuit负责收集这些测试,使我们可以在一个测试中,完成全部的对被测类的多个测试。 TestSuite类实现了Test接口,且可以包含其它的TestSuites。它可以处理加入Test时的所有抛出的异常。 Te

8、stSuite处理测试用例有6个规约(否则会被拒绝执行测试) A 测试用例必须是公有类(Public)B 测试用例必须继承与TestCase类 C 测试用例的测试方法必须是公有的( Public )D 测试用例的测试方法必须被声明为VoidE 测试用例中测试方法的前置名词必须是testF 测试用例中测试方法无任何传递参数TestResult结果类和其它类与接口TestResult结果类集合了任意测试累加结果,通过TestResult实例传递每个测试的Run()方法。TestResult在执行TestCase时如果失败会异常抛出 TestListener接口是个事件监听规约,可供TestRunn

9、er类使用。它通知listener的对象相关事件,方法包括测试开始startTest(Test test),测试结束endTest(Test test),错误,增加异常addError(Test test,Throwable t)和增加失败addFailure(Test test,AssertionFailedError t) TestFailure失败类是个“失败”状况的收集类,解释每次测试执行过程中出现的异常情况。其toString()方法返回“失败”状况的简要描述4. 利用Junit开发一个简单的Java程序(1)File-new-Java project,名称为“HelloWorldW

10、ithJUnit”建立两个文件夹,分别为src和junittestsrc 存放实现主要功能的文件junittest 存放测试功能文件(2)创建测试类选中“HelloWorldWithJUnit”项目中的junittest包文件夹,右键并选择new-other-Junit-Junit Test Case(3)选择“next”,在New Junit Test Case中的name中输入“HelloWorldTest”,在package中输入“junittest”,然后单击“finish”。(4)现在初步计划被测试文件功能非常简单,只有一个方法ReturnValue,作用是返回“HelloWorld

11、”,所以测试类中有对ReturnValue这个方法进行测试的类。当然,测试要能进行,该测试类必须为主类,存在main方法。HelloWorldTest.java的源代码如下:选择run-run as-Junit test 弹出一个Junit窗口,发现在该窗口中有一个红条,这说明存在错误。(5)创建HelloWorld类建立一个HelloWorld类,并输入以下代码: (6)在HelloWorldTest.java中加入import src.*; 此时以Junit测试的方式来运行HelloWorldTest.java,出现了含有绿色的窗口,测试成功。assertEqualspublic stat

12、ic void assertEquals(java.lang.Stringmessage, java.lang.Objectexpected, java.lang.Objectactual)Asserts that two objects are equal. If they are not, an AssertionError is thrown with the given message. If expected and actual are null, they are considered equal. Parameters: message - the identifying me

13、ssage for the AssertionError (null okay) expected - expected value actual - actual valueassertFalsepublic static void assertFalse(java.lang.Stringmessage, booleancondition)Asserts that a condition is false. If it isnt it throws an AssertionError with the given message. Parameters: message - the iden

14、tifying message for the AssertionError (null okay) condition - condition to be checkedassertTruepublic static void assertTrue(java.lang.Stringmessage, booleancondition)Asserts that a condition is true. If it isnt it throws an AssertionError with the given message. Parameters: message - the identifyi

15、ng message for the AssertionError (null okay) condition - condition to be checkedassertNullpublic static void assertNull(java.lang.Stringmessage, java.lang.Objectobject)Asserts that an object is null. If it is not, an AssertionError is thrown with the given message. Parameters: message - the identif

16、ying message for the AssertionError (null okay) object - Object to check or nullassertNotNullpublic static void assertNotNull(java.lang.Stringmessage, java.lang.Objectobject)Asserts that an object isnt null. If it is an AssertionError is thrown with the given message. Parameters: message - the ident

17、ifying message for the AssertionError (null okay) object - Object to check or nullassertSamepublic static void assertSame(java.lang.Stringmessage, java.lang.Objectexpected, java.lang.Objectactual)Asserts that two objects refer to the same object. If they are not, an AssertionError is thrown with the

18、 given message. Parameters: message - the identifying message for the AssertionError (null okay) expected - the expected object actual - the object to compare to expectedassertNotSamepublic static void assertNotSame(java.lang.Stringmessage, java.lang.Objectunexpected, java.lang.Objectactual)Asserts

19、that two objects do not refer to the same object. If they do refer to the same object, an AssertionError is thrown with the given message. Parameters: message - the identifying message for the AssertionError (null okay) unexpected - the object you dont expect actual - the object to compare to unexpe

20、ctedfailpublic static void fail(java.lang.Stringmessage)Fails a test with the given message. Parameters: message - the identifying message for the AssertionError (null okay) See Also: AssertionError实验一 白盒测试方法一、实验目的1、掌握白盒测试基本技术,并能够应用白盒测试技术设计测试用例2、掌握白盒测试中的逻辑覆盖和路径测试方法二、实验任务使用白盒测试方法为下面的程序设计测试用例(使用逻辑覆盖和路

21、径测试方法):程序要求:10个铅球中有一个假球(比其他铅球的重量要轻),用天平三次称出假球。程序设计思路:第一次使用天平分别称5个球,判断轻的一边有假球;拿出轻的5个球,取出其中4个第二次称,两边分别放2个球:如果两边同重,则剩下的球为假球;若两边不同重,拿出轻的两个球称第三次,轻的为假球。 图1 判断假球的程序流程图三、实验要求1、做好实验预习,掌握并熟悉本实验中所使用的测试环境及相应的测试软件2、写出实验报告,内容是:(1)实验目的(2)实验内容 实验源代码(或测试脚本)可不写出,但是一定要写出实验中出现的错误,以及解决错误的方法(3)出错信息及处理方法(4)实验结果,包括实验处理结果和设

22、计心得。单元测试覆盖率-使用CloverClover是对单元测试覆盖率进行统计的软件,在Eclipse中使用Clover,首先使用从下载后把Clover压缩包里的两个文件夹,features和plugins,复制到Eclipse安装目录中替换原来的两个文件夹。1. 打开Eclipse,从Window-Show view-other,可以看到Clover的信息:2还需要导入clover.license。从Preferences-Clover-License进入:并将申请到的的license粘帖到这里,至此Clover已经安装完成,开始进入单元测试。3. 可以对之前已经做过的project进行覆盖

23、率的计算。也可新建了一个project,结构如下:Sample.java和SampleTest.java内容分别是:Java代码 1. packagecom.lyoe.sample; 2. 3. publicclassSample 4. publicIntegeradd(Integera,Integerb) 5. if(a=null|b=null) 6. returnnull; 7. 8. Integersum=newInteger(a.intValue()+b.intValue(); 9. returnsum; 10. 11. package com.lyoe.sample;public c

24、lass Sample public Integer add(Integer a, Integer b) if (a = null | b = null) return null; Integer sum = new Integer(a.intValue() + b.intValue(); return sum; Java代码 1. packagecom.lyoe.sample; 2. 3. importcom.lyoe.sample.Sample; 4. importjunit.framework.TestCase; 5. 6. publicclassSampleTestextendsTes

25、tCase 7. 8. protectedvoidsetUp()throwsException 9. super.setUp(); 10. 11. 12. publicvoidtestAdd() 13. Samplesample=newSample(); 14. Integera=newInteger(1); 15. Integerb=newInteger(2); 16. Integerc=sample.add(a,b); 17. assertNotNull(c); 18. 19. 20. protectedvoidtearDown()throwsException 21. super.tea

26、rDown(); 22. 23. 24. package com.lyoe.sample;import com.lyoe.sample.Sample;import junit.framework.TestCase;public class SampleTest extends TestCase protected void setUp() throws Exception super.setUp(); public void testAdd() Sample sample = new Sample(); Integer a = new Integer(1); Integer b = new I

27、nteger(2); Integer c = sample.add(a, b); assertNotNull(c); protected void tearDown() throws Exception super.tearDown(); 右击JunitInAction工程,选择Properties-Clover。上面有一个Enable Clover in this project,勾上,apply-OK.从Window-Show view-other进入,找到Coverage Explorer,打开,看到Clover选项的相关信息:点击红框内的按钮,会弹出重新构建工程的提示,点击是即可。在C

28、overage Explorer界面下,我们会看到:右击SampleTest.java,选择Run as-JUnit Test,结果如下:可以看到Sample.java的覆盖率为71.4%.Clover还可以生成三种测试报告:PDF/HTML/XML。按钮可以在Coverage Explorer那排的选项按钮里找到(run new report)。实验二 黑盒测试一、实验目的1、掌握黑盒测试基本技术,并能够应用黑盒测试方法设计测试用例2、熟悉黑盒测试中的等价类测试方法和边界值测试方法。二、实验任务使用等价类方法设计下面程序的设计用例:输入三个整数作为边,分别满足一般三角形、等腰三角形和等边三角

29、形。三、实验内容和步骤1、使用等价类划分法设计下面的测试用例:(1)源程序package p1; import java.io.*; public class JTriangle private int b,c,a; private static int x1,x2,x3; private static String s1,s2,s3;public void setA(int a) this.a=a; public void setB(int b) this.b=b;public void setC(int c) this.c=c; public boolean IsTriangle()if(a+bc&a+cb&b+ca&a!=0&b!=0&c!=0)return true;elsereturn false; public JTriangle() public JTriangle(int _a,int _b,i

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

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