Spring Slice Tests, Mocking, and Gradle
Spring
I continue studying for the Spring certification. Yesterday, I reviewed:
- Adding a GET endpoint and testing it with
TestRestTemplate
- Separating concerns using
Spring Data
and the Repository pattern - Using
Optional
Slice Tests
Spring Boot provides a way for test slicing. Yesterday, I practiced using @WebMvcTest
and
MockMvc
to
slice the
testing to include only the web layer. For that, mocking with Mockito
comes in handy with functions like when
,
thenReturn
, and verify
.
Gradle
You can tell Gradle to only run certain tests. Like this:
./gradlew test --tests example.cashcard.CashCardControllerTest