●●● ●●●●● ●●●● ●●●● 一个完整的测试用例 ●●●● ●●0● public class stringiest extends Testcase t protected void setup()( / run before ★/} protected void tearDown ()(/ after */1 public void testsimpleEqual ( string sl new string(abcd)i String s2 new string ("abcd")i assertfrue(Strings not equal s1 equals(s2))i public static void main(string[] args)t junit. textui. TestRunner run (suite ())i
一个完整的测试用例 public class StringTest extends TestCase { protected void setUp(){ /* run before */} protected void tearDown(){ /* after */ } public void testSimpleEqual() { String s1 = new String(“abcd”); String s2 = new String(“abcd”); assertTrue(“Strings not equal”, s1.equals(s2)); } public static void main(String[] args){ junit.textui.TestRunner.run (suite ()); } }
●●● ●●● ●●●●● ●●●● ●●●● ●●●● ●●0● ●HEHE
⚫ HEHE
●●● ●●●●● ●●●● ●●●● 编写测试用例时的几点注意事项 ●●●● ●●0● ●使用 setup()和 teardown(来创建、初始化 和释放测试用例间公共的测试对象及所需的环 境 ●确保测试没有副作用,也就是说测试用例运行 前后系统的状态保持不变 ●确保测试用例间没有依赖关系,每一个测试用 例都能够独立运行
编写测试用例时的几点注意事项 ⚫ 使用setup() 和 tearDown()来创建、初始化 和释放测试用例间公共的测试对象及所需的环 境。 ⚫ 确保测试没有副作用,也就是说测试用例运行 前后系统的状态保持不变 ⚫ 确保测试用例间没有依赖关系,每一个测试用 例都能够独立运行
●●● ●●●●● ●●●● ●●●●● Course Sample ●●●● ●●0● public class student Test extends TestCase i public void testTake Coursed t CourseEvaluation Factory system= CourseEvaluation Factory getinstanceo Course course= factory create Course("OOT","面向对象技术); Student student=factory create Student(001","test") int size course. getStudents(size student take Course(course) assertEquals(size+ 1, course. get Students( sized)
Course Sample public class StudentTest extends TestCase { public void testTakeCourse() { CourseEvaluationFactory system = CourseEvaluationFactory.getInstance(); ICourse course = factory.createCourse("OOT","面向对象技术"); IStudent student = factory.createStudent("001", "test"); int size = course.getStudents().size(); student.takeCourse(course); assertEquals(size+1, course.getStudents().size()); } }