Spring Boot آپ کو ایک testing pyramid دیتا ہے: بغیر Spring کے تیز unit tests، مرکوز slice tests جو context کا حصہ load کرتی ہیں، اور چند full-context integration tests۔ ہر test کے لیے درست سطح چننا یہاں کی senior مہارت ہے۔
Unit test — بالکل Spring نہیں
Constructor injection کا مطلب ہے کہ زیادہ تر service logic کو صفر Spring درکار ہوتا ہے؛ بس collaborators کو mock کریں:
{
mock(PriceRepository.class);
(repo.base()).thenReturn(BigDecimal.TEN);
(repo);
assertThat(svc.priceOf()).isEqualByComparingTo();
}
