资源描述
练习和实验:面向对象技术的类状态测试一.下图是选课系统中的课程(course)类的状态图,根据下图完成1. 给出类 course 的定义,包括属性和方法。2. 例出所有需要测试的类状态3. 列出所有需要测试状态的事件和转换4. 从课程开始状态,到没有分配老师的状态,然后触发事件addProfessor 到分配老师的状态,然后学生选课人数达到 10 人到满员的状态,最后触 发 closeRegistration 事件到提交状态。请为这个状态场景的测试,开发 一个测试驱动类,要编写出伪码。Ic&eRegislrationcaiand Proles:ieduae niimStudttnls =3cloeel-numStLidentB niJrriStucSerits +1高丽 ets _ jdos&Reg istrat sn has Praje弱丁 assigned1. Course 类定义Class course Studentnumber integerprofessor stringissubmit booleanNewCourse()AddProfessor()RemoveProfessor()AddStudent()RemoveStudent()Close()CloseRegistration()Cancel()Getprofessor()Getstudentnum()Getissubmit()2. 类的测试状态 Unassigned, Assigned, Full, Cancel, Committed3. 测试状态的事件和转换状态A事件和转换状态BUnassignedAddProfessor()AssignedRemoveProfessor()UnassignedAddS tuden t()FullUnassignedClose()CancelCloseRegistration()Cancel()AssignedAddS tuden t()FullAssignedClose()CancelCancel()AssignedClose()committedCloseRegistration()fullClose()committedCloseRegistration()fullCancel()cancel4.状态场景的测试类class testscenarioStudentNumProfessorIsSubmitstep1OK Booleanstep2OK Booleanstep3OK Booleanstep4OK Booleanmain() testcase= instantiate newcourse() testcase.addprofessor(“zhangshan”) professor=testcase.getprofessor() if professor=”zhangshan” thenstep1OK=true elsestep1OK=false end if for (I=1;10;I+)testcase.addstudent() studentnum=testcase.getstudentnum() if studentnum =10 thenstep2OK=true elsestep2OK=false end iftestcase.close() issubmit=test.getissubmit() if issubmit=True thenstep3OK=true elsestep3OK=false end ifif step1OK =true and step2OK =true and step3OK =true then return trueelsereturn falseend if
展开阅读全文