본문 바로가기

mockito

Spring boot Throwing Exception test @SpringBootTest class StudentRepositoryTest { @Autowired Student student; @Autowired StudentGrades studentGrades; @MockBean private StudentRepository studentRepository; @Autowired private StudentService studentService; @Autowired private ApplicationContext context; @DisplayName("Throw runtime error") @Test void throwRuntimeError() { Student nullStudent = (Student)context.getBean("Student"); doTh.. 더보기
Spring boot @MockBean Example @SpringBootTest class StudentRepositoryTest { @Autowired Student student; @Autowired StudentGrades studentGrades; @MockBean private StudentRepository studentRepository; @Autowired private StudentService studentService; @BeforeEach void beforeEach() { student.setFirstName("Eric"); student.setLastName("King"); student.setEmailAddress("eric.roby@asdf.com"); student.setStudentGrades(studentGrades); .. 더보기
Spring boot @MockBean @MockBean - includes Mockito @Mock functionality - also adds mock bean to if existing bean is there, the mock bean will replace it - thus making the mock bean available for injection with @Autowired Using @Mock @SpringBootTest class StudentRepositoryTest { @Mock private StudentRepository studentRepository; @InjectMocks private StudentService studentService; } Using @MockBean @SpringBootTest clas.. 더보기
Spring boot Mockito Example - @Mock & @InjectMocks @SpringBootTest class StudentRepositoryTest { @Autowired Student student; @Autowired StudentGrades studentGrades; @Mock private StudentRepository studentRepository; @InjectMocks // inject mock dependencies private StudentService studentService; @BeforeEach void beforeEach() { student.setFirstName("Eric"); student.setLastName("King"); student.setEmailAddress("eric.roby@asdf.com"); student.setStud.. 더보기
Spring boot Test with Mockito Mocking Framworks mockito easymock jmockit Mockito in spring boot mockito framwork is builtin spring boot dependency -> spring-boot-starter-test Mockito Test Process setup set expectations with mock reponses execute call the method want to test assert check the result and verify that it is expected result verify optionally.. verify calls (how many times called etc..) Mokcito Test in Spring boot .. 더보기