Spring Slice Tests, Mocking, and Gradle

Spring

I continue studying for the Spring certification. Yesterday, I reviewed:

  1. Adding a GET endpoint and testing it with TestRestTemplate
  2. Separating concerns using Spring Data and the Repository pattern
  3. 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