Spring Boot testing — @WebMvcTest for controllers, @DataJpaTest for repositories, @SpringBootTest only for integration, MockMvc, @MockBean vs @Mock, AssertJ, @Transactional rollback, @ActiveProfiles, TestContainers
93
89%
Does it follow best practices?
Impact
100%
1.09xAverage score across 5 eval scenarios
Passed
No known issues
Write unit tests for a Spring Boot service that processes payments. The application has:
PaymentService with a method PaymentResult processPayment(PaymentRequest request) that:
PaymentGateway.charge(amount, cardToken) to process the chargePaymentRepository.save(payment)PaymentResult with status and transaction IDPaymentDeclinedException if the gateway declines the chargeIllegalArgumentException if the amount is zero or negativePaymentGateway is an interface for the external payment providerPaymentRepository extends JpaRepository<Payment, Long>Produce a Java test file at src/test/java/com/example/payments/service/PaymentServiceTest.java.
Test at minimum:
Do not produce the application source code -- only the test file.