testing with mock in robotium

0
0

i am using mock for my test in Rbotium. My first test fail and another test pass. i think it is because of that the mock is not ready for the test. but when i add a fake test all of my tests passes.

my fake test:

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

all tests:

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

my mock:

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

before adding fake test, only test_ShowCategoryGamesListFragment_CategoryListActionbarTabClicked() not pass and other test pass but after adding fake test all of them pass.
please help me

  • You must to post comments
0
0

i changed setup n it works.

@Override
protected void setUp() throws Exception {

    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();
}
  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website