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 閱讀(534)
評論(0) 編輯 收藏 所屬分類:
個人學習日記 、
agile