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();
}
