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 tests for a Spring Boot REST controller that manages food orders. The application has this structure:
OrderController handles endpoints: POST /api/orders (create), GET /api/orders/{id} (get by id), GET /api/orders (list all)OrderService contains business logic and is injected into the controllerOrderRepository extends JpaRepository<Order, Long>Order entity has fields: id, customerName, status, items, totalcustomerName is required (not blank), items must not be emptyProduce a Java test file at src/test/java/com/example/orders/controller/OrderControllerTest.java.
Test at minimum:
Do not produce the application source code -- only the test file.