Spring Boot உங்களுக்கு ஒரு testing pyramid-ஐ வழங்குகிறது: Spring இல்லாத வேகமான unit test-கள், context-இன் ஒரு பகுதியை load செய்யும் focused slice test-கள், மற்றும் சில முழு-context integration test-கள். ஒவ்வொரு test-க்கும் சரியான நிலையைத் தேர்ந்தெடுப்பது இங்குள்ள senior திறமை.
Unit test — Spring அறவே இல்லை
Constructor injection என்றால், பெரும்பாலான service logic-க்கு சுழிய (zero) Spring தேவை; வெறுமனே collaborator-களை mock செய்யுங்கள்:
{
mock(PriceRepository.class);
(repo.base()).thenReturn(BigDecimal.TEN);
(repo);
assertThat(svc.priceOf()).isEqualByComparingTo();
}
