$npx skillfedfor your agent

unit-test-application-events

This skill teaches patterns for unit testing Spring ApplicationEvent publishers and @EventListener consumers using JUnit 5 and Mockito, without booting the full Spring context. Learn to mock ApplicationEventPublisher, capture events with ArgumentCaptor, verify listener side effects, and test async event handling. Covers error scenarios and best practices for keeping event tests isolated and deterministic.

unit-test-application-events provides patterns for testing Spring ApplicationEvent publishers and listeners with JUnit 5 and Mockito.

AI-generated summary based on this skill's SKILL.md

311 37 MITupdated by giuseppe-trisciuoglio

Decision gist · record as of 2026-06-22

unit-test-application-events provides patterns for testing Spring ApplicationEvent publishers and listeners with JUnit 5 and Mockito. This skill teaches patterns for unit testing Spring ApplicationEvent publishers and @EventListener consumers using JUnit 5 and Mockito, without booting the full Spring context. Learn to mock ApplicationEventPublisher, capture events with ArgumentCaptor, verify listener side effects, and test async event handling. Covers error scenarios and best practices for keeping event tests isolated and deterministic.

manual: git clone https://github.com/giuseppe-trisciuoglio/developer-kit → cp -r developer-kit/plugins/developer-kit-java/skills/unit-test-application-events ~/.claude/skills/unit-test-application-events
plugins/developer-kit-java/skills/unit-test-application-events/SKILL.md · version 14115fca

Use it when

  • unit-test-application-events covers mocking ApplicationEvent by creating test doubles of ApplicationEventPublisher with Mockito.
  • unit-test-application-events shows how to test @EventListener methods by calling them directly or publishing test events to a mocked.

Verify before relying

Read SKILL.md below before installing (1 file). Open directory: indexed for reading, not audited.

Same gist for agents: .md · .json

Install

giuseppe-trisciuoglio/developer-kit/unit-test-application-events · repository language: Python

Open directory. Skills are indexed for reading, not audited. Review a skill's body before installing it.

Frequently asked questions

AI-generated answers based on this skill's SKILL.md and metadata

How to unit test Spring application events?

unit-test-application-events teaches you to test Spring ApplicationEvent publishers and listeners in isolation using JUnit 5 and Mockito without booting the full context. Mock the ApplicationEventPublisher, use ArgumentCaptor to capture published events, and verify that your @EventListener methods respond correctly. This approach keeps tests fast and deterministic by avoiding Spring's full initialization overhead.

How do I mock ApplicationEvent in Spring Boot?

unit-test-application-events covers mocking ApplicationEvent by creating test doubles of ApplicationEventPublisher with Mockito. Define your custom ApplicationEvent subclass, inject the mocked publisher into your service under test, and use ArgumentCaptor to intercept and assert on events your code publishes. This pattern isolates event logic from Spring's context and lets you verify both event creation and listener behavior.

How can I test @EventListener annotation Spring methods?

unit-test-application-events shows how to test @EventListener methods by calling them directly or publishing test events to a mocked publisher. Use ArgumentCaptor to capture events, then verify your listener's side effects—database calls, state changes, or downstream publishes. For async listeners marked @Async, configure a test executor or use CountDownLatch to synchronize and assert completion without relying on Spring's full event infrastructure.

What's the best way to verify event published in Spring service?

unit-test-application-events recommends mocking ApplicationEventPublisher and capturing events with ArgumentCaptor. Inject the mock into your service, trigger the code path that should publish, then call captor.getValue() or captor.getAllValues() to assert the event type, payload, and properties. This isolates your service test from listener implementations and lets you verify publication logic independently.

How do I test async event handler testing in Spring?

unit-test-application-events covers async event handling by configuring a test executor for @Async @EventListener methods or using synchronization primitives like CountDownLatch. Mock the publisher, trigger publication, wait for the async task to complete, then verify side effects. This ensures your async listeners behave correctly without depending on Spring's full task scheduling or requiring integration tests.

What are best practices for testing event listeners without context?

unit-test-application-events emphasizes keeping event tests isolated: mock ApplicationEventPublisher and listener dependencies, use ArgumentCaptor to verify event flow, test error scenarios separately, and avoid booting Spring. Validate that publishers emit the right events and listeners handle them correctly in unit tests; reserve integration tests for cross-component event propagation. This approach speeds up your test suite and makes event logic easier to debug.

SKILL.md

Rendered from the published skill. Quoted content, verbatim.

Unit Testing Application Events

Overview

Provides actionable patterns for testing Spring ApplicationEvent publishers and @EventListener consumers using JUnit 5 and Mockito — without booting the full Spring context.

When to Use

  • Writing unit tests for event publishers or listeners
  • Verifying that an event was published with correct payload
  • Testing @EventListener method invocation and side effects
  • Testing event propagation through multiple listeners
  • Validating async event handling (@Async + @EventListener)
  • Mocking ApplicationEventPublisher in service tests

Instructions

  1. Add test dependencies: spring-boot-starter, JUnit 5, Mockito, AssertJ
  2. Mock ApplicationEventPublisher: use @Mock on the publisher

(truncated - see the full file via the links below)

File tree — 1 file
plugins/developer-kit-java/skills/unit-test-application-events/SKILL.md

Let your AI agent find skills like this

Example. Real query, live index.

You found this page by searching. An agent finds it by wishing: SkillFed indexes 56,283 agent skills by what they can do, searchable in plain language.

wish › “Write unit tests for Spring ApplicationEvent publishers and listeners without full context”

Give your agent the search over MCP, or paste the wish link into any chat. No install? Search from any chat →

Related skills

unit-test-service-layer
by giuseppe-trisciuoglio · giuseppe-trisciuoglio/developer-kit

Master isolated service layer testing using Mockito to mock repositories and external clients without database or API calls. This skill teaches you to arrange test data, verify method interactions, and handle exception scenarios with AssertJ assertions.

MITupdated Jun 2026
★ 311repo stars
junit-5-skill
by LambdaTest · LambdaTest/agent-skills

This skill equips you to write robust JUnit 5 tests in Java, from basic assertions and exception handling to parameterized test cases and Mockito-driven mocking. It covers lifecycle management, nested test organization, and anti-patterns to avoid, with quick reference commands for Maven and Gradle execution.

MITupdated Jul 2026
★ 339repo stars
unit-test-caching
by giuseppe-trisciuoglio · giuseppe-trisciuoglio/developer-kit

This skill equips you with reusable test patterns for Spring caching annotations without requiring full application context. It covers cache hit/miss behavior, invalidation logic, SpEL key generation, and conditional caching scenarios using in-memory CacheManager.

MITupdated Jun 2026
★ 311repo stars
spring-boot-test-patterns
by giuseppe-trisciuoglio · giuseppe-trisciuoglio/developer-kit

Spring Boot Test Patterns guides you through layered testing strategies—from fast unit tests with mocked dependencies to full integration tests with real databases via Testcontainers. Learn focused slice testing with @DataJpaTest and @WebMvcTest, REST API testing with MockMvc, and container setup using @ServiceConnection for Spring Boot 3.5+.

MITupdated Jun 2026
★ 311repo stars
Java Test Generator
by dawiddutoit · dawiddutoit/custom-claude

Automatically generate well-structured JUnit 5 test cases for Java classes, complete with Mockito mocking, parameterized test scenarios, and edge case handling. The skill follows Arrange-Act-Assert patterns, creates tests for exception handling, verifies mock interactions, and targets high test coverage across service layers and Spring Boot components.

no license declared → metadata onlyupdated Jan 2026
★ 1repo stars
spring-boot-event-driven-patterns
by giuseppe-trisciuoglio · giuseppe-trisciuoglio/developer-kit

Implement event-driven architecture in Spring Boot 3.x using domain events, ApplicationEventPublisher, and Kafka for distributed messaging. This skill covers designing immutable domain events, publishing from aggregate roots, handling events transactionally with @TransactionalEventListener, configuring Kafka producers and consumers, and implementing the outbox pattern for guaranteed event delivery.

MITupdated Jun 2026
★ 311repo stars

More skills unit-test-controller-layer (MIT) · spring-framework (Apache-2.0)

Tags
event-driven-testingpublisher-subscriber-patternsasync-verificationspring-isolation-testingmock-event-flow