白盒测试和黑盒测试试验报告_第1页
白盒测试和黑盒测试试验报告_第2页
白盒测试和黑盒测试试验报告_第3页
白盒测试和黑盒测试试验报告_第4页
白盒测试和黑盒测试试验报告_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

本文格式为Word版,下载可任意编辑——白盒测试和黑盒测试试验报告的对象相关事件,方法包括测试开始startTest(Testtest),测试终止endTest(Testtest),错误,增加异常addError(Testtest,Throwablet)和增加失败addFailure(Testtest,AssertionFailedErrort)

TestFailure失败类是个―失败‖状况的收集类,解释每次测试执行过程中出现的异常状况。其toString()方法返回―失败‖状况的简要描述4.利用Junit开发一个简单的Java程序

(1)File-new-Javaproject,名称为“HelloWorldWithJUnit〞建立两个文件夹,分别为src和junittestsrc存放实现主要功能的文件junittest存放测试功能文件

(2)创立测试类

选中“HelloWorldWithJUnit〞项目中的junittest包文件夹,new-other-Junit-JunitTestCase

右键并选择

(3)选择“next〞,在NewJunitTestCase中的name中输入“HelloWorldTest〞,在package中输入“junittest〞,然后单击“finish〞。

(4)现在初步计划被测试文件功能十分简单,只有一个方法ReturnValue,作用是返回“HelloWorld〞,所以测试类中有对ReturnValue这个方法进行测试的类。当然,测试要能进行,该测试类必需为主类,存在main方法。HelloWorldTest.java的源代码如下:

选择run-runas-Junittest

弹出一个Junit窗口,发现在该窗口中有一个红条,这说明存在错误。(5)创立HelloWorld类

建立一个HelloWorld类,并输入以下代码:

(6)在HelloWorldTest.java中参与importsrc.*;

此时以Junit测试的方式来运行HelloWorldTest.java,出现了含有绿色的窗口,测试成功。

assertEquals

publicstaticvoidassertEquals([java.lang.Stringmessage],java.lang.Objectexpected,java.lang.Objectactual)

Assertsthattwoobjectsareequal.Iftheyarenot,anAssertionErroristhrownwiththegivenmessage.Ifexpectedandactualarenull,theyareconsideredequal.

Parameters:

message-theidentifyingmessagefortheAssertionError(nullokay)expected-expectedvalueactual-actualvalue

assertFalse

publicstaticvoidassertFalse(java.lang.Stringmessage,booleancondition)

Assertsthataconditionisfalse.Ifitisn'titthrowsanAssertionErrorwiththegiven

message.Parameters:

message-theidentifyingmessagefortheAssertionError(nullokay)condition-conditiontobechecked

assertTrue

publicstaticvoidassertTrue(java.lang.Stringmessage,booleancondition)

Assertsthataconditionistrue.Ifitisn'titthrowsanAssertionErrorwiththegiven

message.Parameters:

message-theidentifyingmessagefortheAssertionError(nullokay)condition-conditiontobechecked

assertNull

publicstaticvoidassertNull(java.lang.Stringmessage,java.lang.Objectobject)

Assertsthatanobjectisnull.Ifitisnot,anAssertionErroristhrownwiththegiven

message.

Parameters:

message-theidentifyingmessagefortheAssertionError(nullokay)object-Objecttocheckornull

assertNotNull

publicstaticvoidassertNotNull(java.lang.Stringmessage,java.lang.Objectobject)

Assertsthatanobjectisn'tnull.IfitisanAssertionErroristhrownwiththegiven

message.Parameters:

message-theidentifyingmessagefortheAssertionError(nullokay)

object-Objecttocheckornull

assertSame

publicstaticvoidassertSame([java.lang.Stringmessage],java.lang.Objectexpected,java.lang.Objectactual)

Assertsthattwoobjectsrefertothesameobject.Iftheyarenot,anAssertionErroris

thrownwiththegivenmessage.Parameters:

message-theidentifyingmessagefortheAssertionError(nullokay)

expected-theexpectedobject

actual-theobjecttocomparetoexpected

assertNotSame

publicstaticvoidassertNotSame(java.lang.Stringmessage,java.lang.Objectunexpected,java.lang.Objectactual)

Assertsthattwoobjectsdonotrefertothesameobject.Iftheydorefertothesameobject,anAssertionErroristhrownwiththegivenmessage.Parameters:

message-theidentifyingmessagefortheAssertionError(nullokay)unexpected-theobjectyoudon'texpect

actual-theobjecttocomparetounexpected

Showview->other,可以看到Clover的信息:

2.还需要导入clover.license。从Preferences->Clover->License进入:

并将申请到的的license粘帖到这里,至此Clover已经安装完成,开始进入单元测试。

3.可以对之前已经做过的project进行覆盖率的计算。也可新建了一个project,结构如下:

Sample.java和SampleTest.java内容分别是:

Java代码

1.packagecom.lyoe.sample;2.

3.publicclassSample{

}

returntrue;}}

publicvoidSetTriangle(){try{

BufferedReaderin=newBufferedReader(newInputStreamReader(System.in));

System.out.println(\请输入三角形的三边:\);System.out.println(\);s1=in.readLine();

while(!ISNumble(s1)){

System.out.println(\你输入的不是个数字\);System.out.println(\);s1=in.readLine();}

System.out.println(\);s2=in.readLine();while(!ISNumble(s2)){

System.out.println(\你输入的不是个数字\);System.out.println(\);s2=in.readLine();

}

System.out.println(\);s3=in.readLine();while(!ISNumble(s3)){

System.out.println(\你输入的不是个数字\);System.out.println(\);s3=in.readLine();}}

catch(IOExceptione){}

x1=Integer.parseInt(s1);x2=Integer.parseInt(s2);x3=Integer.parseInt(s3);

setA(x1);setB(x2);setC(x3);}

publicstaticvoidmain(Stringargs[]){JTriangletr=newJTriangle();tr.SetTriangl

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论