?????????????????????????????????????????д??????????????????????????????????????????????????ɡ?????????????????????????????????????????????????
??????????????????Mock/Stub??????????
????????????????????????Mock/Stub??????????????????Щ????????????????????????????????????????Щ???????????????????????class?? ??class BlogDao?? ??????????????????????????class ConfigReader?? ??????????????????????????????class MyStringParser?? ??????????????????к??????????????ж?????????????????????????????????????????????????????????????????磬???????class MyStringProcessor?? ???????MyStringParser?? ???????MyStringProcessor ???????????????MyStringParser ?????????????????????????????????MyStringParser ????????????????????????????????????????????????????????У??????????????????ζ?????????????????????????????ζ?????????????????????????????????????????“?????????????”???ж??????????????????
?????????????????????Mock/Stub???????????????????????????????????????????????????????
????Back to Mock/Stub?? ????????????У????????Mock???????????????????“????”?? “????”????????“????”??“????”???????? ????“????”???????Щ????“????”???????????Mock?????????????????????????????????????????????????????Stub / Mock objects??????????????Stub / Mock ????????????????Stub / Mock ??????а??????????????????????????????“?????????”??“?????????”????????????????д???е????????????????????
????????????????????Stub / Mock????????????????磬?? xUnit Test Patterns ?????????????????????Test Double?????stunt double ???????????????????????????????
???? ·  Dummy Object
???? ·  Test Stub
???? ·  Test Spy
???? ·  Mock Object
???? ·  Fake Object
???????У?Fake Object????????????????????????????????????????磬 InMemoryBlogDao??????? SqlBlogDao???????????????????????????? BlogDao ??? ??????????
??????????????????????Dummy Object??Test Stub??Test Spy??????????Stub????μ?Mock Object ?????Mock??
?????????Dummy Object????????????Dummy Object???????????????????????????????????????????????п???????ò??????????磬????BlogService ??? BlogDao????????????BlogService ?????????????????????BlogDao?????????????? new BlogService(new NullBlogDao())??  NullBlogDao ??Dummy Object?????????????????????????????????????????
????Test Stub ???????? ??????????????ε??????????????????????????????ò???????????????????????????????????Щ??????????磬???????HttpContextStub ????????????HttpContext?? ??????????SessionId?? ResquestParameter ??????????????????????Щ??????????????????getSessionId() ??????????????????????????ε????????????????
????Test Spy ???????????????????????????????????????BlogService ????????????????TestSpy??
public class BlogDaoTestSpy implements BlogDao {
public Blog savedBlog = null;
public void save(Blog blog) {
savedBlog = blog;
}
}
  ??????????д????????
@Test
public void testSaveBlog(){
Blog blog = new Blog();
blogService.save(blog);
assertEqual(blog?? ((BlogDaoTestSpy)blogDao).savedBlog);
}
???????????????????????blogService.save(blog) ????blogDao??savedBlog ?????仯?????????????blogDao??????????????????????????仯???