??????????????????????AppPreferencesTest????????Android Junit Test???????У??????Junit????п?????????????????
?????????????δ?????????????????????????
public void testSecondAndMoreRun() {
prefs.isFirstRun();
assertFalse(prefs.isFirstRun());
}
????????????????????????????testSecondAndMoreRun???????????????????????????????????????????е?AppPreferences??????????′???
public boolean isFirstRun() {
boolean orgVal = isFirstRun;
isFirstRun = false;
return orgVal;
}
??????????????в???????AppPreferencesTest?????????????????????????????????????
??????????μ???????п????????????????в????????????????????????
?????????????????AppPreferences??????
@Override
public void onCreate() {
super.onCreate();
}
public void onTerminate() {
super.onTerminate();
}
public boolean isFirstRun() {
prefs = getSharedPreferences("mhcs"?? MODE_PRIVATE);
boolean orgVal = isFirstRun;
isFirstRun = false;
Editor editor = prefs.edit();
editor.putBoolean(PREF_IS_FIRST_RUN?? false);
editor.commit();
return orgVal;
}
public void setFirstRun(boolean isFirstRun) {
this.isFirstRun = isFirstRun;
}
public final static String PREF_IS_FIRST_RUN = "isFirstRun";
private SharedPreferences prefs = null;
private boolean isFirstRun = true;
???????????????????????????
public void testFirstRunTrue() {
createApplication();
prefs = getApplication();
Editor editor = mContext.getSharedPreferences("mhcs"?? 0).edit();
editor.clear().commit();
assertTrue(prefs.isFirstRun());
}
public void testSecondAndMoreRun() {
createApplication();
prefs = getApplication();
assertFalse(prefs.isFirstRun());
}
?????????????????testFirstRunTrue?????У????SharedPreferences????????????????????????????????С?
???????в????????????????????????????????????????????????