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 JPA repository for a product catalog. The application has:
Product entity with fields: id (Long), name (String), category (String), price (BigDecimal), inStock (boolean)ProductRepository extends JpaRepository<Product, Long> with custom query methods:
List<Product> findByCategory(String category)List<Product> findByPriceLessThan(BigDecimal maxPrice)List<Product> findByInStockTrue()Produce a Java test file at src/test/java/com/example/catalog/repository/ProductRepositoryTest.java.
Test at minimum:
findByCategory returns matching productsfindByCategory returns empty list when no matchfindByPriceLessThan returns products under the price thresholdfindByInStockTrue returns only in-stock productsDo not produce the application source code -- only the test file.