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 閱讀(536) 評論(0)  編輯  收藏 所屬分類: 個人學習日記 、agile
          主站蜘蛛池模板: 增城市| 剑河县| 嘉祥县| 汕头市| 喀喇| 昌吉市| 酉阳| 黑山县| 库尔勒市| 安塞县| 潮安县| 靖安县| 雷州市| 枣强县| 平武县| 天镇县| 邓州市| 关岭| 鸡西市| 灵山县| 巍山| 迁安市| 长岛县| 嵩明县| 扎囊县| 牡丹江市| 枣阳市| 麟游县| 曲麻莱县| 五台县| 房产| 榆社县| 新和县| 张家口市| 嫩江县| 土默特左旗| 高唐县| 淮南市| 察哈| 万年县| 乐平市|