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-2/

Order Controller Tests

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 controller
  • OrderRepository extends JpaRepository<Order, Long>
  • Order entity has fields: id, customerName, status, items, total
  • Validation: customerName is required (not blank), items must not be empty

Output

Produce a Java test file at src/test/java/com/example/orders/controller/OrderControllerTest.java.

Test at minimum:

  1. Creating an order returns 201 with the created order
  2. Creating an order with empty customerName returns 400
  3. Getting a nonexistent order returns 404
  4. Listing orders returns 200 with an array

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

evals

tile.json