2023年新版Junit单元测试实验报告.docx
《2023年新版Junit单元测试实验报告.docx》由会员分享,可在线阅读,更多相关《2023年新版Junit单元测试实验报告.docx(18页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、软件工程与计算I实验名称:实验报告Jun it单元测试实验分组号:实验人:班 级:学 号:陈燕珠H13软件工程实验指导教师:陈国明实验场地:花都校区实验楼709实验时间:2023、6、9成 绩:c lass total b e fore extends abed i m p 1 emen t s wage p ublic dou b 1 e mo n e y()t ota 1 price=(en dHou r-sta rtHour)*3. 4+(endM i nut e-s t art M i nut e)/ 6 0*3. 4 ;。 re t u r n to t alp r ice;。 c
2、1 a ss t o t a lafer ext e nds abed implements wage 。 public d ouble money()。 t ot a Ipri c e= (2-start Ho ur-l)*3. 4+( 6 0start M i n w te) /60 * 3.4+end Hour * 3.9 + e ndMin u te/6 0*3. 9;。 r e tu r n tot a Ip r ice;。6 )p u b 1 i c c 1 a s s a b c pu b lie sta t ic void main( S tring a r gs ) 。 ab
3、 c d. s tar t Hou r=a b cd. in puts t artHour();。a b c d . e dHour= abed, inp u t En d Hou r ();0abe d.startMinute=3b c d.inpu t StartMi。 abed.e nd Minute=ab c d.i n pu t EndMinute();o if ( a bed. endHo u r0) 。tot a 1 afer aa=new t o ta I a f e r();。 o aa. 5 tar tHour=abcd. sta rtHou r;。0 a a. s / a
4、r fc d . sta rtMi n u te;o 。aa. endHo ur= a bed.endHo ur;。a a. endMinute=a b c d . endMin u t e ;。Sys t em. out.p r inti n (mone y is +aa.mo ney(); 。els e i f (a b cd. en d Ho ur= 2 1 &abcd. e ndH our ,p. start/Iour=22:, p.startMinute;,p. en d H our=2 3 ;。 s p .endMinut g=0; a c t u a 1= p. m o n ey
5、 ();。Assert, a s ser t Equ a /s(ex p ec t e ds, actual,0.0 f ); c a tc h (Ex c e p t i on e )。 e.prints t ackTrac e();。) , e o o 六.实验结果及结论运营程序,其覆盖情况如下:import java.util.Scanner; interface wagepublic double money();class abed staticintstartHour;staticintstartMinute;staticintendHour;staticintendMinute;
6、doubletotalprice;public static int inputStartHour() int aaa0;System.out.printIn(please input starthour 18-23);Scanner bbb=new Scanner(System.in);String str=bbb.nextLine(); try if (str.matchesCCl8-9|20-3-) (System.out. println( correct*); aaa-Integer.parseJnt(str);return aaa;) else throw new Exceptio
7、n(Exception);catch(Exception ex)System.out.println(please input again*); inputStartHour();N return aaa;/inputpublic static int inputStartMinute()int aaa=0;System.out.println(,please input startminute);Scanner bbb=new Scanner(System.in);String str=bbb.nextLine();try if (s5.matches(0-50-9 | 0-9)(Syste
8、m.out.println(correct);aaa-Integer.parselnt(str); return aaa;)else throw new Exception(*Exception);catch(Exception ex)System.out.printlnOlease input again);inputStartMinuteO ;) return aaa; /inputpublic static int inputEndHour()int aaa=0;System.out.printIn(please input Endhour 21-23 0-4);Scanner bbb=
9、new Scanner(System.in);String strbbb.nextLine();try (if (str.matches(,2l-3 | 0-4-) (System. out. printin(correct);aaa-Integer.parselnt(str);return aaa;else throw new Exception( Exception );catch(Exception ex)System.out.println(please input again); inputEndHour();return aaa;/inputpublic static int in
10、putEndMinute()int aaa=0;System.out.println(please input endminute);Scanner bbb=new Scanner(System.in);String str=bbb.nextLine();try if (str.matches(0-50-9|0-9)System.out.printIn(correct); aaa=Integer.parselnt(str); return aaa;else throw new Exception(Exception);catch(Exception ex)System.out.println(
11、please input again); inputEndMinute();return aaa;/inputclass totalbefore extends abed implements wage( public double money()totalprice=(endHour-startHour)*3.4+(enc/Minute-startAlinute)/60*3.4; return totalprice;)class totalafer extends abed implements vwage Opublic double money()totalprice=(24-start
12、Hour-l)*3.4+(60-startMinute)/60*3.4+endHour*3.9+endMinute/60*3.9j return totalprice;)public class abcpublic static void main(String args)abed.startHour=abcd.inputStartHour();abed.endHour=abcd.inputEndHour();abed. startAJinute=abcd. inputStartMinute();abed.endMinute=abcd.inputEndMinute();if (abed.end
13、HourQ) totalafer aa=new totalafer();aa.startHour=abcd.startHour;aa.startMinute=abcd.startMinute;aa.endHour=abcd.endHour;aa.endHinute-abcd.endMinute;System. out. print In ( money is ,+aa.money();)else if(abed.enc/Hour=21&abcd.endHour=23) totalbefore aa=new totalbefore();aa.startHour=abcd.startHour;aa
14、.startHour=abcd.startHour;aa.startNinute=abcd.startMinute)aa.endHour=abcd.endHour;aa. endAJinute=abcd. endMinute;System.out.println(money is +aa.money();)图3 :测试代码覆盖分析+ import junit.framework.TestCase;jpublic class abcTest extends TestCase I /Festpublic void testtotalprice()double actual;double expec
15、teds = 3.4;try (abc ppp=new abc();ppp.取消图5:导出覆盖率报告abcTest (2015-6-14 21:52:19)ElementCoverage Covered Instruct). Missed Instruct). Total Instructions tzabc= 63.5%209120329defaultElementMissed Instruct ions Cov.Missed Branches Cov.Missed CxtyMissed Lines Missed MethodsMissed ClassesQabcd”b 战 b胧492053
16、0501Qtotalafer0%n/a2233221 1Oabc63%阚466200201Q abcTest9第n/a022180201Q abcTestTest 10%n/a1 111111 1Qtotalbefore =100%n/a02030201Total120 of 32964%9 of 1644%1122329831426abcElenentMissed Instructions-r Cov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethodsMissed Classessre 附:401122329831426Total120
17、 of 32964%9 of 164筋1122329831426ahrTxt f2ni5-fi-14 91 S?191totalbeforeElementMissed Instruct ions Cov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods0 mcney()n/a0102016 totalbefore。二100Kn/a010101Total0 of 23iom0 of 0n/a020302abcElementMissed Instruct ions Cov.Missed BranchesCov.Missed CxtyMiss
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2023 新版 Junit 单元测试 实验 报告
限制150内