pojo in action一书里面的TDD例子应该都是基于jmock的前一版本的,新一点的jmock的很多写法都不同。自己做了一下,还是不理解得很好。自己先发一个简单的做法,还并不知有什么做得不妥的地方。
首先建立测试用例:

public class PlaceOrderServiceTests extends MockObjectTestCase{

 Mockery context = new Mockery();
   
    public void testUpdateRestaurant_good() throws Exception{
     //setup
     PlaceOrderService service = new PlaceOrderService();
     final RestaurantRepository restaurantRepository  =  context.mock(RestaurantRepository.class);
     final String restaurantId = "1";
     final String pendingOrderId = "1";
     //expectations
     context.checking(new Expectations(){{
      allowing(restaurantRepository).findRestaurant(restaurantId,pendingOrderId);
      }});
     //execute
     service.updateRestaurant(restaurantId,pendingOrderId);
     //verify
     context.assertIsSatisfied();
    }
}
然后分别建立相应的类和接口:

public interface RestaurantRepository {

 Restaurant findRestaurant(String restaurantId, String pendingOrderId);

}

public class Restaurant {

}

public class PlaceOrderService {

 public void updateRestaurant(String restaurantId, String pendingOrderId) {
  // TODO Auto-generated method stub
  
 }

}

posted on 2007-10-30 09:18 lzj520 阅读(526) 评论(0)  编辑  收藏 所属分类: 个人学习日记agile

只有注册用户登录后才能发表评论。


网站导航: