Spring Boot మీకు ఒక testing pyramid ను ఇస్తుంది: Spring లేని fast unit tests, context లో భాగాన్ని load చేసే focused slice tests, మరియు కొన్ని full-context integration tests. ప్రతి test కు సరైన level ను ఎంచుకోవడం ఇక్కడ senior నైపుణ్యం.
Unit test — అస్సలు Spring లేదు
Constructor injection అంటే చాలా service logic కు సున్నా Spring అవసరం; కేవలం collaborators ను mock చేయండి:
{
mock(PriceRepository.class);
(repo.base()).thenReturn(BigDecimal.TEN);
(repo);
assertThat(svc.priceOf()).isEqualByComparingTo();
}
