Spring Boot testing — @WebMvcTest for controllers, @DataJpaTest for repositories, @SpringBootTest only for integration, MockMvc, @MockBean vs @Mock, AssertJ, @Transactional rollback, @ActiveProfiles, TestContainers
93
89%
Does it follow best practices?
Impact
100%
1.09xAverage score across 5 eval scenarios
Passed
No known issues
Write integration tests for a Spring Boot user registration flow. The application has:
UserController with endpoints:
POST /api/users/register -- accepts {"username": "...", "email": "...", "password": "..."}, returns 201 with the created user (without password)GET /api/users/{id} -- returns user profileUserService handles registration logic: validates input, checks for duplicate email, hashes password, saves via UserRepositoryUserRepository extends JpaRepository<User, Long>Produce a Java test file at src/test/java/com/example/users/UserRegistrationIntegrationTest.java.
Also produce src/test/resources/application-test.yml with the test database configuration.
Test at minimum:
Do not produce the application source code -- only the test file and test configuration.