Android Studio???????????
???????????? ???????[ 2016/5/23 14:26:20 ] ????????Android ???????
??????????????????????????????????????
?????????????????????System.out.println????????????????????????????????????????Log.d()????????????
???????????????????java??Unit test????????Android???????android.util.log.Log????????????Android?????????androidTest??
??????дAndroid????????
????1??Android???????????????
????2????androidTest????????java??????????InstrumentationTestCase
??????д???public void????????????????????????test?????????testPublishSubject?????????@Test???
public class TestSubject extends InstrumentationTestCase {
private static final String LOG_TAG = "test";
public void testPublishSubject() {
PublishSubject<String> stringPublishSubject = PublishSubject.create();
stringPublishSubject.subscribe(new Observer<String>() {
@Override
public void onCompleted() {
Log.d(LOG_TAG?? "Observable completed");
}
@Override
public void onError(Throwable e) {
}
@Override
public void onNext(String s) {
Log.d(LOG_TAG?? "Observer consumed " + s);
}
});
stringPublishSubject.onNext("hello world");
stringPublishSubject.onCompleted();
}
}
???????????к?????Android Monitor????test???LOGTAG???????????????Log
????Android Studio???????????Activity??????Activities?????????????????????ActivityInstrumentationTestCase2???????
??????androidTest????????java??????????ActivityInstrumentationTestCase2??????????????Activity????????
??????дsetUp?????????Context
??????д???public void????????????????????????test?????????testStart?????????@Test???
public class TestActivity extends ActivityInstrumentationTestCase2<MainActivity> {
private Context ctx;
public TestActivity() {
super(MainActivity.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
ctx = getActivity().getApplicationContext();
}
public void testStart() {
Intent intent = new Intent(ctx?? MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ctx.startActivity(intent);
}
}
????????????????????????????????????????????Activity
???????????????
????????InstrumentationTestCase??ActivityInstrumentationTestCase2??android.test????????????????????
????· ActivityUnitTestCase
????· MockApplication
????· ServiceTestCase
??????
???·???
??????????????????
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