Spring Boot તમને એક testing pyramid આપે છે: Spring વગરના ઝડપી unit tests, context નો ભાગ load કરતા કેન્દ્રિત 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();
}
