2014-04-21 4 views
2

Rbotium에서 테스트하기 위해 모의 테스트를 사용하고 있습니다. 내 첫 번째 시험은 실패하고 다른 시험은 통과합니다. 나는 모의이 시험 준비가되어 있지 않기 때문이라고 생각합니다. 하지만 가짜 테스트를 추가하면 모든 테스트가 통과됩니다.Robotium의 모의 테스트

내 가짜 시험 :

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

변경된 설정이 작동합니다.

@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(); 

} 
을 던진다