dilipsundarraj1/kafka-for-developers-using-spring-boot-v2/testing-skills
Claude Code and agent skill by dilipsundarraj1/kafka-for-developers-using-spring-boot-v2
- community
- ext:[{"type":"config","description":"Configuration overrides"}]
Checking that the SKILL.md file is still in the repository.
Unit and integration testing patterns for this Spring Boot 4.0 Kafka consumer project using JUnit Jupiter, Testcontainers 2.x, EmbeddedKafka, and MockMvc.
Install
npx vskill@latest install dilipsundarraj1/kafka-for-developers-using-spring-boot-v2/testing-skillsSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
About this skill
This project has three categories of tests, all under src/test/java/com/learnkafka/. There are no mocks — every test runs against real infrastructure (embedded Kafka broker, Testcontainers PostgreSQL).
Technology Stack
| Component | Version | Notes | |
|---|---|---|---|
| JUnit Jupiter | 6.x | Via spring-boot-starter-test (Spring Boot 4.0) | |
| Spring Boot Test | 4.0.3 | @SpringBootTest, @AutoConfigureMockMvc | |
| Testcontainers | 2.x | @ImportTestcontainers + @ServiceConnection (NOT the old @Testcontainers/@Container) | |
| EmbeddedKafka | (managed) | @EmbeddedKafka from spring-kafka-test | |
| MockMvc | (managed) | Import AutoConfigureMockMvc from org.springframework.boot.webmvc.test.autoconfigure (Spring Boot 4.0 package) | |
| Jackson 3.x | (managed) | tools.jackson.databind.ObjectMapper (NOT com.fasterxml.jackson) for test JSON serialization |
Test Dependencies (build.gradle)
Test Configuration
File: src/test/resources/application.yml
server.port: 0— random port to avoid conflicts.spring.flyway.clean-disabled: false— allow Flyway clean in tests.spring.jpa.hibernate.ddl-auto: none— Flyway owns the schema; never usecreateorupdate.- No `spring.datasource.*` —
@ServiceConnectionauto-wires JDBC URL/username/password from the Testcontainer. spring.kafka.consumer.auto-offset-reset: latest— overridden toearliestin Kafka integration tests via@TestPropertySource.
Test Categories
1. Kafka Consumer Integration Tests (consumer/)
File: LibraryEventsConsumerIntegrationTest.java Purpose: End-to-end test — produce to EmbeddedKafka → real consumer picks up → persists to Testcontainers PostgreSQL.
Annotations:
Key patterns:
- Declares
@ServiceConnection static PostgreSQLContainer<?>for the database. @BeforeEachbuilds aKafkaTemplate<Integer, LibraryEventDto>usingEmbeddedKafkaBroker.getBrokersAsString()withIntegerSerializer+JsonSerializer.- Produces messages via
kafkaTemplate.send(...).get(10, TimeUnit.SECONDS). - Uses a polling helper
waitForRecordCount(expectedCount, timeoutSeconds)that pollslibraryEventRepository.count()until the async consumer has persisted the expected records. - Asserts against the real database via
libraryEventRepository.findAll()andbookRepository.findAll().
Template:
2. Service Integration Tests (service/)
File: LibraryEventServiceIntegrationTest.java Purpose: Test LibraryEventService.processEvent() directly — bypasses Kafka entirely, exercises DTO→Entity mapping and JPA persistence against real PostgreSQL.
Annotations:
Key patterns:
- Constructs
ConsumerRecord<Integer, LibraryEventDto>manually via abuildConsumerRecord()helper — no Kafka broker needed. - Calls
libraryEventService.processEvent(consumerRecord)synchronously. - Asserts the two-step persist:
LibraryEventsaved first (IDENTITY-generated ID), thenBooksaved with FK set.
Helper:
Template:
3. REST Controller Integration Tests (controller/)
File: BookControllerIntegrationTest.java Purpose: Test BookController REST endpoints via MockMvc against real PostgreSQL.
Annotations:
Key patterns:
- Uses
MockMvc(autowired) for HTTP assertions —status(),jsonPath(),content(). - Uses Jackson 3
tools.jackson.databind.ObjectMapperfor JSON serialization in request bodies. @BeforeEachcleansbookRepository(child first due to FK).- Uses a
persistBookWithLibraryEvent()helper to set up test data that needs a LibraryEvent FK. - Tests all CRUD operations: GET (all, by ID, 404), POST (201, 400 validation), PUT (200, 404), DELETE (204, 404).
Helper for test data setup:
Template:
Key Conventions
Data Cleanup
- Always use
@BeforeEach(not@AfterEach) — ensures a clean DB even if the previous test failed. - Delete child entities first due to FK constraints:
bookRepository.deleteAll()thenlibraryEventRepository.deleteAll().
Testcontainers Setup
- Use
@ImportTestcontainers(Spring Boot 4.0) — NOT the old@Testcontainersfrom TC 1.x. - Use
@ServiceConnectionon the container field — NOT@DynamicPropertySource. - Container must be
staticand use the typedPostgreSQLContainer(notGenericContainer).
Assertions
- Use JUnit Jupiter assertions (
assertEquals,assertNotNull,assertTrue,assertFalse) — no AssertJ or Hamcrest. - For MockMvc use
MockMvcResultMatchers(status(),jsonPath(),content()).
Naming Convention
- Test class:
{ClassName}IntegrationTest.java - Test method:
{methodUnderTest}_{scenario}_{expectedBehavior}()— e.g.,processEvent_ADD_shouldPersistLibraryEventAndBook().
No Mocks
- This project does not use Mockito or mocks. All tests run against real infrastructure.
- Kafka consumer tests use
@EmbeddedKafka; service tests bypass Kafka by constructingConsumerRecorddirectly.
Jackson Version
- Test code uses Jackson 3.x:
tools.jackson.databind.ObjectMapper— NOTcom.fasterxml.jackson.databind.ObjectMapper.
Running Tests
Prerequisites
- Docker must be running — Testcontainers starts PostgreSQL containers automatically.
- No need to run
compose.yamlor start Kafka externally — tests are self-contained.
Reference
- See
docs/7_INTEGRATION_TESTING_WITH_TESTCONTAINERS.mdfor detailed Testcontainers 2.x setup, lifecycle, and troubleshooting. - See
docs/5_CONSUMER_CONCEPTS_HANDS_ON.mdfor Kafka consumer concepts tested in the consumer integration test.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckinglibrary-events-consumer-v2/.github/skills/testing-skills/SKILL.md
Popularity
- Repository stars
- 114
- Repository forks
- 216
- 7-day trend score
- 0
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Extension points
configConfiguration overrides
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/dilipsundarraj1/kafka-for-developers-using-spring-boot-v2/testing-skills)