Android测试驱动开发实践
|
public class AppPreferencesTest extends ApplicationTestCase<AppPreferences> {
public AppPreferencesTest(Class<AppPreferences> applicationClass) {
super(applicationClass);
}
}
|
|
public void testFirstRunTrue() {
assertTrue(prefs.isFirstRun());
}
private AppPreferences prefs = new AppPreferences();
|
|
public boolean isFirstRun() {
return isFirstRun;
}
public void setFirstRun(boolean isFirstRun) {
this.isFirstRun = isFirstRun;
}
private boolean isFirstRun = true;
|
|
public void testSecondAndMoreRun() {
prefs.isFirstRun();
assertFalse(prefs.isFirstRun());
}
|
|
public boolean isFirstRun() {
boolean orgVal = isFirstRun;
isFirstRun = false;
return orgVal;
}
|
|
@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());
}
|