#Unit Testing
1 messages · Page 1 of 1 (latest)
<@&1004656351647117403> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
directly ? nah
if u do testing on the method(s) that include it, it should pass trough
How to correctly cover the code with unit testing, in case these errors can only be thrown during integration testing?
mock it
Won't this turn the unit test into an integration test?
not really. Your going to test the method that uses these right ?
Yeah, my method throws this exception if Spring cannot transform the json into an object
Without context application and MockMvc, this exception cannot be thrown...
can u test the happy path ?
Of course
@Test
void testSendEmail_callServiceAndIsOk() throws MessagingException, IOException {
SendEmailRequest request = new SendEmailRequest();
request.setToEmail("[email protected]");
request.setFromEmail("[email protected]");
request.setSubject("Love letter from f3n1b00t");
request.setText("Hello world!");
request.setHtml(false);
SendEmailResponse response = emailController.sendEmail(request);
assertTrue(response.isOk());
assertEquals("Email was sent", response.getMessage());
verify(emailService).sendEmail(request);
}
Detected code, here are some useful tools:
@Test
void testSendEmail_callServiceAndIsOk() throws MessagingException, IOException {
SendEmailRequest request = new SendEmailRequest();
request.setToEmail("[email protected]");
request.setFromEmail("[email protected]");
request.setSubject("Love letter from f3n1b00t");
request.setText("Hello world!");
request.setHtml(false);
SendEmailResponse response = emailController.sendEmail(request);
assertTrue(response.isOk());
assertEquals("Email was sent", response.getMessage());
verify(emailService).sendEmail(request);
}
dont know the code ofc, does html=true trigger any of those 2 ?
No, but SendEmailRequest has an array of attachments, and if the user sends wrong json it will be thrown