敏捷开发的必要技巧----Wingel 翻译自 Essential Skills for Agile Development
厦门:王伟杰 Wingel MSN: wingel_wang@hotmail.com
邮箱: seewingel@gmail.com 博客: http://wingel.javaeye.com
第 1 页
第
第第
第 12 章
章章
章 单元测试
单元测试单元测试
单元测试
单元测试
单元测试单元测试
单元测试
假定你在写一个 CourseCatalog 类,这个类用来记录一些课程的信息:
class CourseCatalog {
CourseCatalog() {
...
}
void add(Course course) {
...
}
void remove(Course course) {
...
}
Course findCourseWithId(String id) {
...
}
Course[] findCoursesWithTitle(String title) {
...
}
}
class Course {
Course(String id, String title, ...) {
}
String getId() {
...
}
String getTitle() {
...
}
}
为了保证 CourseCatalog 这个类没有 bug,我们应该测试它。比如,为了知道它的 add 方法是不是真的能够
将一个 Course 加进去,我们用下面的代码来测试:
class TestCourseCatalog {
static void testAdd() {