2014-04-21 64 views
2

我正在使用模擬器進行Rbotium的測試。我的第一次測試失敗了,再次測試通過。我認爲這是因爲模擬沒有準備好進行測試。但是當我添加一個假測試時,所有的測試都通過了。在模擬機器人中進行測試

我的假測試:

public void test_ShowA_HomeActionbarTabClicked() { 
     assertEquals("",""); 
    } 

所有測試:

public void test_ShowCategoryGamesListFragment_CategoryListActionbarTabClicked() { 
     //click on Categories action bar tab 

     getSolo().clickOnText(getSolo().getCurrentActivity().getString(R.string.title_section1)); 
     getSolo().clickOnText(getSolo().getCurrentActivity().getString(R.string.games_title)); 
     Assert.assertTrue(getSolo().searchText("GAME_CATEGORY TITLE")); 



    } 
    public void test_ShowCategoryAppsListFragment_CategoryListActionbarTabClicked() { 
     //click on Categories action bar tab 
     getSolo().clickOnText(getSolo().getCurrentActivity().getString(R.string.title_section1)); 
     getSolo().clickOnText(getSolo().getCurrentActivity().getString(R.string.apps_title)); 
     Assert.assertTrue(getSolo().searchText("APP_CATEGORY TITLE")); 

    } 

    public void test_ShowCategoryAppsListRowCountFragment_CategoryListActionbarTabClicked() { 
     //click on Categories action bar tab 
     getSolo().clickOnText(getSolo().getCurrentActivity().getString(R.string.title_section1)); 
     getSolo().clickOnText(getSolo().getCurrentActivity().getString(R.string.apps_title)); 
     ListView listView = getSolo().getView(ListView.class, 0); 
     assertEquals(5, listView.getCount()); 

    } 
    public void test_ShowCategoryGamesListRowCountFragment_CategoryListActionbarTabClicked() { 

     //click on Categories action bar tab 
     getSolo().clickOnText(getSolo().getCurrentActivity().getString(R.string.title_section1)); 
     getSolo().clickOnText(getSolo().getCurrentActivity().getString(R.string.games_title)); 
     ListView listView = getSolo().getView(ListView.class, 0); 
     assertEquals(5, listView.getCount()); 

    } 

我的模擬:

protected void setUp() throws Exception { 
     super.setUp(); 
     getMockRestServer().addMockCallResponseHandler(RestCommandFactoryImpl.getInstance().getBaseUrl() + "/category" 
       , "[ {\"id\":\"1\", \"parentId\":\"12\",\"iconURL\":\"MyIcon\",\"title\":\"APP_CATEGORY TITLE1\"}," + 
       "{\"id\":\"2\", \"parentId\":\"12\",\"iconURL\":\"MyIcon\",\"title\":\"APP_CATEGORY TITLE2\"} , " + 
       "{\"id\":\"3\", \"parentId\":\"12\",\"iconURL\":\"MyIcon\",\"title\":\"APP_CATEGORY TITLE3\"} ," + 
       "{\"id\":\"4\", \"parentId\":\"12\",\"iconURL\":\"MyIcon\",\"title\":\"APP_CATEGORY TITLE4\"} ," + 
       "{\"id\":\"5\", \"parentId\":\"12\",\"iconURL\":\"MyIcon\",\"title\":\"APP_CATEGORY TITLE5\"}," + 
       "{\"id\":\"6\", \"parentId\":\"11\",\"iconURL\":\"MyIcon\",\"title\":\"GAME_CATEGORY TITLE1\"}, " + 
       "{\"id\":\"7\", \"parentId\":\"11\",\"iconURL\":\"MyIcon\",\"title\":\"GAME_CATEGORY TITLE2\"}," + 
       "{\"id\":\"8\", \"parentId\":\"11\",\"iconURL\":\"MyIcon\",\"title\":\"GAME_CATEGORY TITLE3\"}," + 
       "{\"id\":\"9\", \"parentId\":\"11\",\"iconURL\":\"MyIcon\",\"title\":\"GAME_CATEGORY TITLE4\"}," + 
       "{\"id\":\"10\", \"parentId\":\"11\",\"iconURL\":\"MyIcon\",\"title\":\"GAME_CATEGORY TITLE5\"}," + 
       "{\"id\":\"11\", \"parentId\":null,\"iconURL\":\"MyIcon\",\"title\":\"بازی ها\"}," + 
       "{\"id\":\"12\", \"parentId\":null,\"iconURL\":\"MyIcon\",\"title\":\"برنامه ها\"}]"); 

     getMockRestServer().addRestCommandToMock("category", new GetAllCategoriesRestCommand()); 
     getMockRestServer().start(); 


    } 

添加假測試之前,只有test_ShowCategoryGamesListFragment_CategoryListActionbarTabClicked()不及格等測試通過,但後加入假測試全部通過。 請幫我

回答

0

我改變了設置n它的工作原理。

@Override 保護無效設置()拋出異常{

MockRestServer mockRestServer = new MockRestServer(); 
    mockRestServer.addMockCallResponseHandler(RestCommandFactoryImpl.getInstance().getBaseUrl() + "/category" 
      , "[ {\"id\":\"1\", \"parentId\":\"12\",\"iconURL\":\"MyIcon\",\"title\":\"APP_CATEGORY TITLE1\"}," + 
      "{\"id\":\"2\", \"parentId\":\"12\",\"iconURL\":\"MyIcon\",\"title\":\"APP_CATEGORY TITLE2\"} , " + 
      "{\"id\":\"3\", \"parentId\":\"12\",\"iconURL\":\"MyIcon\",\"title\":\"APP_CATEGORY TITLE3\"} ," + 
      "{\"id\":\"4\", \"parentId\":\"12\",\"iconURL\":\"MyIcon\",\"title\":\"APP_CATEGORY TITLE4\"} ," + 
      "{\"id\":\"5\", \"parentId\":\"12\",\"iconURL\":\"MyIcon\",\"title\":\"APP_CATEGORY TITLE5\"}," + 
      "{\"id\":\"6\", \"parentId\":\"11\",\"iconURL\":\"MyIcon\",\"title\":\"GAME_CATEGORY TITLE1\"}, " + 
      "{\"id\":\"7\", \"parentId\":\"11\",\"iconURL\":\"MyIcon\",\"title\":\"GAME_CATEGORY TITLE2\"}," + 
      "{\"id\":\"8\", \"parentId\":\"11\",\"iconURL\":\"MyIcon\",\"title\":\"GAME_CATEGORY TITLE3\"}," + 
      "{\"id\":\"9\", \"parentId\":\"11\",\"iconURL\":\"MyIcon\",\"title\":\"GAME_CATEGORY TITLE4\"}," + 
      "{\"id\":\"10\", \"parentId\":\"11\",\"iconURL\":\"MyIcon\",\"title\":\"GAME_CATEGORY TITLE5\"}," + 
      "{\"id\":\"11\", \"parentId\":null,\"iconURL\":\"MyIcon\",\"title\":\"بازی ها\"}," + 
      "{\"id\":\"12\", \"parentId\":null,\"iconURL\":\"MyIcon\",\"title\":\"برنامه ها\"}]"); 

    mockRestServer.addRestCommandToMock("category", new GetAllCategoriesRestCommand()); 
    mockRestServer.start(); 
    super.setUp(); 

} 
相關問題