Robolectric?????????
?????liucloo ???????[ 2016/5/30 11:15:37 ] ?????????????????? ???????
?????????buildActivity??setupActivity?????????Activity?????????????????setupActivity????Activity????????????н?Σ???buildActivity?????????
????public static <T extends Activity> ActivityController<T> buildActivity(Class<T> activityClass) {
????return ActivityController.of(shadowsAdapter?? activityClass);
????}
????public static <T extends Activity> T setupActivity(Class<T> activityClass) {
????return ActivityController.of(shadowsAdapter?? activityClass).setup().get();
????}
????public ActivityController<T> setup() {
????return create().start().postCreate(null).resume().visible();
????}
??????2????????????
????ActivityController????Activity????????????????з?????????????Service?????????
??????3??????????
????Robolectric??????????????????Activity??е?????????????????MainActivity??д???????
MainActivity
button = (Button) findViewById(R.id.test1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("Success");
}
});
TestDemoTest
@Before
public void beforeTest() throws Exception {
Log.i(TAG?? "beforeTest()");
mainActivity = Robolectric.buildActivity(MainActivity.class).setup().get();//???????????
button = (Button) mainActivity.findViewById(R.id.test1);
}
@Test
public void btn1(){
button.performClick();
}
??????Robolectric?д?Log?????**System.out**??Android??Log????????????Adb??????Ч??
??????4????????
????Robolectric????????Junit??assert??????????????????????????Junit??assert???????
????assertNotNull(); //?ж??????????
????assertNull();
????assertEquals(); //?ж???????????????“???”
????assertTrue(); //?ж?????????true
????assertFalse();
????assertNotSame();
????assertSame(); //?ж????????????????????????
??????5??????????????
???????????У????????????????????????????????????棬???????????????????????????????????????????????????????????е????????????????????????????????????????????????????????????????????????????????????????????case?б???б???????????е????????Χ?????????????????????????????????????б??м???????????????棬?????е?case????????????????????????????б???д??????????
??????????????????????????????????????????????????????????????????????????????????????д??????????????????????????и??????????????????????????????????case?б???????????????????в???case??
????????滮??????????????????????????????????????????????????????????
????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11