CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/springboot-testing

Spring Boot testing — @WebMvcTest for controllers, @DataJpaTest for repositories, @SpringBootTest only for integration, MockMvc, @MockBean vs @Mock, AssertJ, @Transactional rollback, @ActiveProfiles, TestContainers

93

1.09x
Quality

89%

Does it follow best practices?

Impact

100%

1.09x

Average score across 5 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

task.mdevals/scenario-4/

Product Repository Tests

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()

Output

Produce a Java test file at src/test/java/com/example/catalog/repository/ProductRepositoryTest.java.

Test at minimum:

  1. findByCategory returns matching products
  2. findByCategory returns empty list when no match
  3. findByPriceLessThan returns products under the price threshold
  4. findByInStockTrue returns only in-stock products
  5. Saving and retrieving a product works correctly

Do not produce the application source code -- only the test file.

evals

tile.json