版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
本文格式为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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 锂硅负极材料电化学测试-洞察及研究
- 2025年智能手环五年迭代续航能力报告
- 房地产金融与物业管理企业可持续发展-洞察及研究
- 电视节目中的循环经济模式与可持续经营实践-洞察及研究
- 地质环境变化对土壤有机质与结构关系的影响研究-洞察及研究
- 高效疫情预测与预警模型-洞察及研究
- 2025年民警述职报告
- 服务器端CSS缓存策略及其优化方法-洞察及研究
- 高等教育资源分配与区域创新能力提升研究-洞察及研究
- 安全隐患大排查工作总结
- 雨课堂学堂在线学堂云《劳动教育(西安理大 )》单元测试考核答案
- 2025年特种作业人员危险化学品安全作业(化工自动化控制仪表)考试题库及答案
- 人社局公益性岗位笔试题目及答案
- 2025年华住集团酒店考试题库
- 《建设工程施工合同示范文本》(GF-2022-0201) 核心条款与使用指南
- 2025年超星尔雅学习通《数据分析与统计》考试备考题库及答案解析
- 2025纪检监察应知应会试题库与参考答案
- 2025年高考浙江卷(6月)物理真题(解析版)
- 吹膜机日常维护保养计划表
- 湖南省长沙市一中集团2025-2026学年七年级上学期11月期中联考英语试题(含解析无听力原文及音频)
- 《西方经济学》-宏观经济学下-含教学辅导和习题解答
评论
0/150
提交评论