Spring Boot Mockito Support: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 1: | Line 1: | ||
=External= | =External= | ||
* https://www.baeldung.com/injecting-mocks-in-spring | * https://www.baeldung.com/injecting-mocks-in-spring | ||
* https://spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4#mocking-and-spying | |||
=Internal= | =Internal= |
Revision as of 01:13, 3 October 2021
External
- https://www.baeldung.com/injecting-mocks-in-spring
- https://spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4#mocking-and-spying
Internal
Overview
TODO: https://spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4#mocking-and-spying
Mocks will be automatically reset across tests.
Example
@RunWith(SpringRunner.class)
@SpringBootTest
public class SomeTest {
@Autowired
private TestRestTemplate restTemplate;
@MockBean
private SomeService someService;
@Before
public void setup() {
// this stubs behavior
given(someService.getSomething("blah")).willReturn(new Something("blah"));
}
@Test
public void test() {
restTemplate.getForEntity("/{username}/something, String.class, "blue");
}
}