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

criteria.jsonevals/scenario-2/

{
  "context": "Tests whether the agent proactively uses @WebMvcTest instead of @SpringBootTest for controller tests, uses @MockBean for service dependencies, and follows Spring Boot testing best practices. The task does not specify which test annotations to use -- the agent should choose @WebMvcTest on its own.",
  "type": "weighted_checklist",
  "checklist": [
    {
      "name": "Uses @WebMvcTest not @SpringBootTest",
      "description": "The test class uses @WebMvcTest(OrderController.class) instead of @SpringBootTest. @WebMvcTest loads only the web layer for faster, more focused controller tests. The agent was NOT told which annotation to use.",
      "max_score": 15
    },
    {
      "name": "@MockBean for OrderService",
      "description": "The test class uses @MockBean to mock OrderService, not @Mock or a real instance. @MockBean replaces the bean in the Spring context.",
      "max_score": 12
    },
    {
      "name": "MockMvc autowired and used",
      "description": "MockMvc is autowired with @Autowired and used via mockMvc.perform() to make HTTP requests.",
      "max_score": 10
    },
    {
      "name": "Mockito when/thenReturn for stubbing",
      "description": "The test uses Mockito when().thenReturn() or when().thenThrow() to stub service method behavior for different test scenarios.",
      "max_score": 8
    },
    {
      "name": "Status code assertions",
      "description": "Tests assert correct HTTP status codes: isCreated() for POST success, isBadRequest() for validation failure, isNotFound() for missing resource, isOk() for GET success.",
      "max_score": 10
    },
    {
      "name": "jsonPath response body assertions",
      "description": "Tests use jsonPath() to assert on response JSON content (e.g., customerName, id, error message).",
      "max_score": 8
    },
    {
      "name": "Validation rejection test",
      "description": "A test verifies that an invalid request (empty customerName) returns 400 Bad Request.",
      "max_score": 8
    },
    {
      "name": "Not found test",
      "description": "A test verifies that getting a nonexistent order returns 404, with the service stubbed to throw an exception.",
      "max_score": 8
    },
    {
      "name": "Content type set on POST",
      "description": "POST requests set .contentType(MediaType.APPLICATION_JSON) on the MockMvc request.",
      "max_score": 5
    },
    {
      "name": "No @DirtiesContext used",
      "description": "The test does not use @DirtiesContext. Controller slice tests with @MockBean do not need context reset.",
      "max_score": 6
    },
    {
      "name": "AssertJ or proper assertion style",
      "description": "Uses AssertJ assertThat() for non-MockMvc assertions, or consistently uses MockMvc .andExpect() chains. Does not mix in JUnit assertEquals for response validation.",
      "max_score": 5
    },
    {
      "name": "No unnecessary @SpringBootTest or full context",
      "description": "Does not load a full application context, database, or repository beans. The test is purely a web layer slice test.",
      "max_score": 5
    }
  ]
}

evals

tile.json