#Unit Testing

1 messages · Page 1 of 1 (latest)

frosty marsh
#

Should I cover this code with unit tests?

faint stoneBOT
#

<@&1004656351647117403> please have a look, thanks.

faint stoneBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

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.

inland bramble
#

directly ? nah

#

if u do testing on the method(s) that include it, it should pass trough

frosty marsh
inland bramble
#

mock it

frosty marsh
inland bramble
#

not really. Your going to test the method that uses these right ?

frosty marsh
#

Without context application and MockMvc, this exception cannot be thrown...

inland bramble
#

can u test the happy path ?

frosty marsh
# inland bramble 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);
    }
faint stoneBOT
# frosty marsh Of course ```java @Test void testSendEmail_callServiceAndIsOk() throws M...

Detected code, here are some useful tools:

Formatted code
@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);
}
inland bramble
#

dont know the code ofc, does html=true trigger any of those 2 ?

frosty marsh