Skip to content

Instantly share code, notes, and snippets.

@galaxyfeeder
Created December 6, 2014 13:47
Show Gist options
  • Save galaxyfeeder/d1ddf061ec281afb90a6 to your computer and use it in GitHub Desktop.
Save galaxyfeeder/d1ddf061ec281afb90a6 to your computer and use it in GitHub Desktop.
Mifos Test Dashboard
package com.mifos.mifosxdroid.tests;
import android.app.Activity;
import android.app.Fragment;
import android.app.Instrumentation;
import android.test.ActivityInstrumentationTestCase2;
import android.test.TouchUtils;
import android.test.ViewAsserts;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import com.mifos.mifosxdroid.OfflineCenterInputActivity;
import com.mifos.mifosxdroid.R;
import com.mifos.mifosxdroid.online.CentersActivity;
import com.mifos.mifosxdroid.online.ClientSearchFragment;
import com.mifos.mifosxdroid.online.DashboardFragmentActivity;
import com.mifos.mifosxdroid.online.LogoutActivity;
import com.mifos.utils.FragmentConstants;
/**
* Created by Gabriel Esteban on 06/12/14.
*/
public class DashboardFragmentActivityTest extends ActivityInstrumentationTestCase2<DashboardFragmentActivity> {
DashboardFragmentActivity dashboardActivity;
EditText et_searchById;
Button bt_searchClient;
ListView lv_searchResults;
TextView tv_title_search;
ClientSearchFragment searchFragment;
public DashboardFragmentActivityTest() {
super(DashboardFragmentActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
dashboardActivity = getActivity();
searchFragment = (ClientSearchFragment) getActivity().getSupportFragmentManager().findFragmentByTag(FragmentConstants.FRAG_CLIENT_SEARCH);
et_searchById = (EditText) dashboardActivity.findViewById(R.id.et_search_by_id);
bt_searchClient = (Button) dashboardActivity.findViewById(R.id.bt_searchClient);
lv_searchResults = (ListView) dashboardActivity.findViewById(R.id.lv_searchResults);
tv_title_search = (TextView) dashboardActivity.findViewById(R.id.tv_title_search_results);
assertNotNull(getInstrumentation());
}
@SmallTest
public void testFragmentIsNotNull() {
assertNotNull(searchFragment);
}
@SmallTest
public void testViewsAreNotNull() {
assertNotNull(et_searchById);
assertNotNull(bt_searchClient);
assertNotNull(lv_searchResults);
assertNotNull(tv_title_search);
}
@SmallTest
public void testViewsAreOnTheScreen() {
final View decorView = dashboardActivity.getWindow().getDecorView();
ViewAsserts.assertOnScreen(decorView, et_searchById);
ViewAsserts.assertOnScreen(decorView, bt_searchClient);
ViewAsserts.assertOnScreen(decorView, lv_searchResults);
ViewAsserts.assertOnScreen(decorView, tv_title_search);
}
@SmallTest
public void testNullInput(){
//checking if the text field is empty
String expected = "";
String actual = et_searchById.getText().toString();
assertEquals(expected, actual);
//clicking the button
TouchUtils.clickView(this, bt_searchClient);
}
@SmallTest
public void testClientListFragmentShowed(){
//clicking the button
//getInstrumentation().invokeMenuActionSync(dashboardActivity, R.id.mItem_list, 0);
//Chekcing fragment is in BackStrack
final Fragment backstrack = (Fragment) dashboardActivity.getSupportFragmentManager().getBackStackEntryAt(0);
assertEquals(backstrack, searchFragment);
//checking client list fragment is shown using the listview
final ListView listview = (ListView) dashboardActivity.findViewById(R.id.lv_clients);
final View decorView = dashboardActivity.getWindow().getDecorView();
ViewAsserts.assertOnScreen(decorView, listview);
this.sendKeys(KeyEvent.KEYCODE_BACK);
}
@MediumTest
public void testCenterListActivityStarted(){
Instrumentation.ActivityMonitor monitor = getInstrumentation().addMonitor(CentersActivity.class.getName(), null, false);
//clicking the button
getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
//getInstrumentation().invokeMenuActionSync(getActivity(), R.id.item_centers, 0);
Activity startedActivity = getInstrumentation().waitForMonitorWithTimeout(monitor, 6000);
assertNotNull(startedActivity);
assertEquals(true, getInstrumentation().checkMonitorHit(monitor, 1));
this.sendKeys(KeyEvent.KEYCODE_BACK);
}
@MediumTest
public void testOfflineActivityStarted(){
Instrumentation.ActivityMonitor monitor = getInstrumentation().addMonitor(OfflineCenterInputActivity.class.getName(), null, false);
//clicking the button
getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
//getInstrumentation().invokeMenuActionSync(getActivity(), R.id.item_centers, 0);
Activity startedActivity = getInstrumentation().waitForMonitorWithTimeout(monitor, 2000);
assertNotNull(startedActivity);
assertEquals(true, getInstrumentation().checkMonitorHit(monitor, 1));
this.sendKeys(KeyEvent.KEYCODE_BACK);
}
@MediumTest
public void testLogoutActivityStarted(){
Instrumentation.ActivityMonitor monitor = getInstrumentation().addMonitor(LogoutActivity.class.getName(), null, false);
//clicking the button
getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
//getInstrumentation().invokeMenuActionSync(getActivity(), R.id.item_centers, 0);
Activity startedActivity = getInstrumentation().waitForMonitorWithTimeout(monitor, 2000);
assertNotNull(startedActivity);
assertEquals(true, getInstrumentation().checkMonitorHit(monitor, 1));
this.sendKeys(KeyEvent.KEYCODE_BACK);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment