| name | java-spring-testing |
| description | Run Java/Spring Boot tests and debug failures. Use when fixing backend tests, implementing new features with tests, or debugging test failures. |
| allowed-tools | Bash, Read, Edit, Grep |
Java Spring Boot Testing
Test Execution
Run tests with:
cd /workspaces/claudeplus
./gradlew backend:test # All tests
./gradlew backend:test --tests "*TaskControllerTest*" # Specific test class
./gradlew backend:test --tests "*TaskControllerTest.testMethod*" # Specific method
Testing Patterns
This project uses JUnit 5 with Mockito and Spring's @WebMvcTest:
Controller Test Structure
@WebMvcTest(TaskController.class)
class TaskControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private TaskService taskService;
@Test
void shouldReturnAllTasks() throws Exception {
when(taskService.findAll()).thenReturn(List.of(task));
mockMvc.perform(get("/api/tasks"))
.andExpect(status().isOk())
.andExpect(jsonPath("$[0].title").value("Task 1"));
}
}
Mockito Patterns
when(mock.method()).thenReturn(value)- Stub return valuesverify(mock).method()- Verify interactions@MockBean- Create Spring-managed mockArgumentCaptor<T>- Capture arguments for assertions
Common Test Fixes
- 404 Not Found: Check endpoint path matches controller mapping
- Mock not returning: Ensure
when()matches exact method signature - JSON parsing errors: Verify
@RequestBodyand content type headers - CORS issues: Check
@CrossOriginannotation on controller
Test Location
Tests are in: /backend/src/test/java/com/claudeplus/demo/