반응형
@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
class StudentRepositoryTest {
//Create mock for the repository
@MockBean
private StudentRepository studentRepository;
//inject dependencies
@Autowired
private StudentSersvice studentService;
}
반응형
'SpringBoot' 카테고리의 다른 글
Spring boot Private field and method Test (0) | 2022.05.22 |
---|---|
Spring boot Throwing Exception test (0) | 2022.05.22 |
Spring boot Mockito Example - @Mock & @InjectMocks (0) | 2022.05.22 |
Spring boot Test with Mockito (0) | 2022.05.22 |
Unit Test - ParameterizedTest (0) | 2022.05.21 |