backend-test-generator
Spring Boot 1�� `�tXX � L��@ �i L��| JUnit 5@ Mockito| ��X� �1X� ��. Controller, Service, Repository t�� \ L��| ��<\ �1Xp� �pt�i��.
When & Why to Use This Skill
This Claude skill automates the generation of comprehensive backend test suites for Spring Boot applications. It streamlines the development process by automatically creating high-quality unit and integration tests using JUnit 5 and Mockito, covering critical layers including Controllers, Services, and Repositories to ensure robust code quality and reliability.
Use Cases
- Automated Unit Testing: Rapidly generate MockMvc-based tests for Spring Boot Controllers to validate REST API endpoints, request mapping, and status codes.
- Service Layer Validation: Create isolated business logic tests using Mockito to mock dependencies and verify complex service-level interactions.
- Data Persistence Testing: Generate @DataJpaTest suites for Repositories to ensure custom queries and CRUD operations work correctly with the database.
- Integration Testing Setup: Streamline the creation of @SpringBootTest configurations to verify the seamless interaction between different application components.
- Legacy Code Coverage: Quickly increase test coverage for existing Spring Boot projects by analyzing source files and generating missing test cases.
| name | backend-test-generator |
|---|---|
| description | Spring Boot 1�� `� tXX � L��@ �i L��| JUnit 5@ Mockito| ��X� �1X� ��. Controller, Service, Repository t�� \ L��| ��<\ �1Xp� �pt�i��. |
| allowed-tools | Read, Grep, Glob |
Backend Test Generator (Spring Boot)
t ��@ Spring Boot 1�� T�| �X� JUnit 5@ Mockito| ��\ L�� T�| ��<\ �1i��.
�� �
L�� ��
- � L��: Controller, Service, Repository � t� L��
- �i L��: API ���x� �i L�� (@SpringBootTest)
�� ��
- ��l: Spring Boot 2.x/3.x
- L�� �l: JUnit 5, Mockito, MockMvc, TestRestTemplate
- L� �l: Maven, Gradle
- ��: Java, Kotlin
� \8�
1��: ���m � �
Git diff| �t �� |D Ux:
git diff HEAD
git status --short
�L (4<\ 1�� |D �� �X:
- Controller:
*Controller.java,src/main/java/**/controller/** - Service:
*Service.java,*ServiceImpl.java,src/main/java/**/service/** - Repository:
*Repository.java,src/main/java/**/repository/** - Entity:
*Entity.java,src/main/java/**/entity/**,src/main/java/**/domain/**
2��: T� �
�� |D }� �L ��| E:
- �\ � T�
- �� T� ��Ș
- �\� REST ���x� (@GetMapping, @PostMapping �)
- �� D�Ȥ \�
- DTO Entity ���m
- Xt1 �� ���m
3��: L�� � �
| ��� 0| \ L�� \�D �:
Controller L��
- \�:
templates/controller-test.md8� - �l: MockMvc, @WebMvcTest
- ��: HTTP �� T�, Q� , �T
Service L��
- \�:
templates/service-test.md8� - �l: Mockito, @ExtendWith(MockitoExtension.class)
- ��: D�Ȥ \�, x ��, ���X
Repository L��
- \�:
templates/repository-test.md8� - �l: @DataJpaTest, TestEntityManager
- ��: CRUD ��, �@ ��
�i L��
- \�:
templates/integration-test.md8� - �l: @SpringBootTest, TestRestTemplate
- ��: � API \�
4��: L�� | �1/�pt�
L�� | X �Y
Spring Boot \ lp| 0�:
src/main/java/com/example/UserController.java�src/test/java/com/example/UserControllerTest.javasrc/main/java/com/example/UserService.java�src/test/java/com/example/UserServiceTest.javasrc/main/java/com/example/UserRepository.java�src/test/java/com/example/UserRepositoryTest.java
L�� t�� �� �Y
- � L��:
{ClassName}Test.java - �i L��:
{ClassName}IntegrationTest.java
0t L�� |t �� ��
- |D }� � L�� T� E
- �� T�� ް L�� �pt�
- �\� 0�� \ L�� �
- Deprecated L�� p
- \� � Ux
5��: �� �� �1
�L �<\ ��| ��:
=
���m �� D�
=� � �� |:
- src/main/java/com/example/UserController.java (Controller)
- src/main/java/com/example/UserService.java (Service)
� L�� �1 ...
�1 D�:
- src/test/java/com/example/UserControllerTest.java (5 test cases)
testGetUser_Success
testGetUser_NotFound
testCreateUser_Success
testCreateUser_ValidationError
testDeleteUser_Success
- src/test/java/com/example/UserServiceTest.java (6 test cases)
testFindUserById_Success
testFindUserById_NotFound
testCreateUser_Success
testCreateUser_DuplicateEmail
testUpdateUser_Success
testDeleteUser_Success
=� L�� 䄬� �: 85%
L�� �� �l���
�1 �� L��� �L 0 D �qt| i��:
�� 0
- L�� T܅t �UX� $� (test{MethodName}_{Scenario} (4)
- Given-When-Then (4
- L�� Žt� � XtX� JL
- Mock/Stubt X� ��(
- �� t�| ��
Controller L�� 0
- MockMvc| ��X� HTTP �� L��
- ��/Q� �,T ��
- x x�� L�� (@ControllerAdvice)
- x�/x L�� (Security � �)
Service L�� 0
- D�Ȥ \� ��
- Repository Xt1 Mocking
- ���X ّ Ux
- �@ x �� L��
Repository L�� 0
- @DataJpaTest ��
- CRUD �� ��
- �@ �� T� L��
- } pt ��
�� �
# �� � 8�
backend-test-generator
# �� ��
"UserController� \ L�� �1t"
"1�� ���m� \ L�� �1t"
"UserService L�� �pt�t"
�X�m
- Mock ��: � DB� x� API| 8�X� J�] Mock ��
- L�� ��: L��� Ž<\ � �t| h
- **
x �**: � L���t� ��| h - X� �� L��: � 䄬� �t D� �� ��
- Spring Context: �D�X� � �M��| \�X� JL
D Xt1
Maven (pom.xml)
<dependencies>
<!-- JUnit 5 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Mockito -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<!-- H2 Database for testing -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Gradle (build.gradle)
dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.mockito:mockito-core'
testRuntimeOnly 'com.h2database:h2'
}
8� ��
�8\ \�� � �L |�D 8�X8�:
templates/controller-test.md- Controller L�� \�templates/service-test.md- Service L�� \�templates/repository-test.md- Repository L�� \�templates/integration-test.md- �i L�� \�references/spring-boot-testing-guide.md- Spring Boot L�� t�