[size=large][b]1.1 Testing[/b] [/size]
[size=large]
TDD——测试驱动开发,意味着你需要为你实际书写的每一部分代码书写测试。也意味着你将率先书写测试。测试是衡量代码是否完成所需工作的一种手段,在写完相对应的代码后,测试可以保证代码实现了测试的功能。
你编的每个类都将有它所对应的测试类,在1.1节中,StudentTest类就是Student类的测试类。
[img]/upload/attachment/74189/58383d25-dd53-3315-be81-834f401ce6fc.bmp[/img]
StudentTest类将不得不创建Student类的对象,并且对这些对象发送消息,一旦所有的消息发送成功,就证明这个类可以正常工作。很明显,就像图中的连线所表示的一样,StudentTest是依赖于Student类的;相反,Student类并不依赖于StudentTest类,应该向被测试类隐藏测试类的实现。
[quote] Test-driven development means that you will write tests for virtually every bit of code. It also means that you will write the tests first. The tests are a means of specifying what the code needs to do. After writing the corresponding code, the tests are run to ensure that the code does what the tests specify.
Each class you code will have a corresponding test class. In Figure 1.1, StudentTest is the test class for the production class Student.
StudentTest will have to create objects of class Student, send messages to these objects, and prove that once all the messages have been sent, things are as expected. StudentTest is thus dependent on Student, as shown by the navigable association in the diagram. Conversely, Student is not dependent on StudentTest: The production classes you build should know nothing about the tests written for them.[/quote][/size]
[size=large]
TDD——测试驱动开发,意味着你需要为你实际书写的每一部分代码书写测试。也意味着你将率先书写测试。测试是衡量代码是否完成所需工作的一种手段,在写完相对应的代码后,测试可以保证代码实现了测试的功能。
你编的每个类都将有它所对应的测试类,在1.1节中,StudentTest类就是Student类的测试类。
[img]/upload/attachment/74189/58383d25-dd53-3315-be81-834f401ce6fc.bmp[/img]
StudentTest类将不得不创建Student类的对象,并且对这些对象发送消息,一旦所有的消息发送成功,就证明这个类可以正常工作。很明显,就像图中的连线所表示的一样,StudentTest是依赖于Student类的;相反,Student类并不依赖于StudentTest类,应该向被测试类隐藏测试类的实现。
[quote] Test-driven development means that you will write tests for virtually every bit of code. It also means that you will write the tests first. The tests are a means of specifying what the code needs to do. After writing the corresponding code, the tests are run to ensure that the code does what the tests specify.
Each class you code will have a corresponding test class. In Figure 1.1, StudentTest is the test class for the production class Student.
StudentTest will have to create objects of class Student, send messages to these objects, and prove that once all the messages have been sent, things are as expected. StudentTest is thus dependent on Student, as shown by the navigable association in the diagram. Conversely, Student is not dependent on StudentTest: The production classes you build should know nothing about the tests written for them.[/quote][/size]