ฉันยังใหม่กับการทดสอบหน่วยใน Android และความพยายามของฉันคือ assertTrue
ว่าข้อมูลถูกส่งไปยังวิธีการสำเร็จและบันทึกใน SharedPreferences
นี่คือการทดสอบของฉันจนถึงตอนนี้:
public class AuthTest {
Authorization authorization = new Authorization();
@Before
public void init() {
MockitoAnnotations.initMocks(this);
}
@Test
public void test_IfAuthIsSaved() {
//test if the auth object is saved in the auth object is saved as a..
//..json string in Shared preferences
Auth auth = mock(Auth.class);
authorization.saveAuth(auth);
//test if the auth is received and saved to sharedpreferences
}
}
วิธี saveAuth:
public void saveAuth(Auth auth) {
editor.putString("USER_AUTH", new Gson().toJson(auth));
editor.commit();
}
การยืนยันนี้จะมีลักษณะอย่างไร?