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
Add test infrastructure to an existing Spring Boot bookstore application. The app uses PostgreSQL in production and has:
BookController with GET /api/books and POST /api/booksBookService for business logicBookRepository extends JpaRepository<Book, Long>Book entity with fields: id, title, author, isbn, priceThe project currently has no tests. Set up the test infrastructure and write sample tests for each layer.
Produce:
src/test/resources/application-test.yml -- test database configurationsrc/test/java/com/example/bookstore/controller/BookControllerTest.java -- controller slice testsrc/test/java/com/example/bookstore/repository/BookRepositoryTest.java -- repository slice testsrc/test/java/com/example/bookstore/BookstoreIntegrationTest.java -- integration testEach test file should contain at least 2 test methods. Do not produce the application source code.