public class MainActivityTest extends ActivityInstrumentat ionTestCase

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
public class MainActivityTest extends
ActivityInstrumentationTestCase2<MainActivity> {
private static final int ADAPTER_COUNT = 7;
MainActivity mActivity;
DrawerAdapter mAdapter;
ActionBarDrawerToggle mDrawerToggle;
public MainActivityTest() {
super(MainActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
setActivityInitialTouchMode(false);
mActivity = getActivity();
mAdapter = new DrawerAdapter(mActivity, new ArrayList<String>(
Arrays.asList(mActivity.getResources().getStringArray(
R.array.main_menu_loged))));
}
public void testDrawerCapacity() {
assertNotNull(mAdapter);
assertEquals(ADAPTER_COUNT, mAdapter.getCount());
}
public void testDrawerOpened() {
final View drawer = mActivity.findViewById(android.R.id.home);
assertNotNull(drawer);
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
drawer.requestFocus();
drawer.performClick();
}
});
}
public void testSearchButton() {
final View view = mActivity.findViewById(R.id.search);
assertNotNull(view);
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
view.requestFocus();
view.performClick();
}
});
}
}