Salve a tutti e grazie per star leggendo la mia domanda.
Devo creare degli unit test della mia applicazione che utilizza Firebase ed essendo nuovo al testing e avendo delle scadenze (esame universitario) non so come approcciarmi al testing di un metodo che utilizza Firebase.
La mia app rispetta il pattern MVVM e uno dei metodi che vorrei testare è il seguente:
Grazie in anticipo del tuo tempo
Devo creare degli unit test della mia applicazione che utilizza Firebase ed essendo nuovo al testing e avendo delle scadenze (esame universitario) non so come approcciarmi al testing di un metodo che utilizza Firebase.
La mia app rispetta il pattern MVVM e uno dei metodi che vorrei testare è il seguente:
Java:
public void register(String email, String password, String username) {
firebaseAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(ContextCompat.getMainExecutor(application), (Task<AuthResult> task) -> {
if (task.isSuccessful()) {
userMutableLiveData.postValue(firebaseAuth.getCurrentUser());
userModel.createUser(username, email);
ToastMaker.makeSuccessToast(application, application.getString(R.string.msg_toast_user_create_successfully));
} else {
try {
throw task.getException();
} catch (FirebaseAuthWeakPasswordException e) {
ToastMaker.makeErrorToast(application, application.getString(R.string.msg_toast_error_password));
} catch (FirebaseAuthInvalidCredentialsException e) {
ToastMaker.makeErrorToast(application, application.getString(R.string.msg_toast_invalid_credential));
} catch (FirebaseAuthUserCollisionException e) {
ToastMaker.makeErrorToast(application, application.getString(R.string.msg_toast_user_already_register));
} catch (Exception e) {
ToastMaker.makeErrorToast(application, application.getString(R.string.msg_toast_generic_registration_error) + task.getException().getMessage());
}
}
});
}
Grazie in anticipo del tuo tempo