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

User Registration Integration Tests

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 profile
  • UserService handles registration logic: validates input, checks for duplicate email, hashes password, saves via UserRepository
  • UserRepository extends JpaRepository<User, Long>
  • The production database is PostgreSQL

Output

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:

  1. Registering a new user returns 201 and the user can be retrieved via GET
  2. Registering with a duplicate email returns 409 Conflict
  3. Registering with invalid input (missing username) returns 400
  4. Getting a nonexistent user returns 404

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

evals

tile.json