Spring Boot तुम्हाला एक testing pyramid देते: Spring शिवाय जलद unit tests, context चा भाग load करणाऱ्या केंद्रित slice tests, आणि काही 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();
}
