samedi 23 juillet 2016

How can I write some tests such that they don't send Email while testing?

I am sending an email to user on form submission. I am having issue while testing. I am testing sendConfirmationEmailForSubmission, and form submission. But while testing form submission it sends mail every time. And I have a lot of combinations for testing form submission. I am wasting my quota of emails by sending emails while submission testing as I am testing sendEmail function seperately. Can anyone please help me with this.

SubmitAction submits the form and sends email. To send email submitAction calls sendConfirmationEmailForSubmission().

public void sendConfirmationEmailForSubmission(String userId)
    throws EntityDoesNotExistException {

Assumption.assertFalse(ERROR_NULL_PARAMETER, userId == null );

EmailsLogic.sendConfirmationEmailForSubmission(userId);
}

I think instead of using above function I should use it like this one and pass userId = null while testing form submssion ?

public void sendConfirmationEmailForSubmission(String userId)
    throws EntityDoesNotExistException {

if (userId == null ) {
    EmailsLogic.sendConfirmationEmailForSubmission(userId);
    }
}

Aucun commentaire:

Enregistrer un commentaire