Back to Skills

unit-test-config-properties

Provides patterns for unit testing `@ConfigurationProperties` classes with `@ConfigurationPropertiesTest`. Validates property binding, tests validation constraints, verifies default values, checks type conversions, and mocks property sources for Spring Boot configuration properties. Use when testing application configuration binding, validating YAML or application.properties files, verifying environment-specific settings, or testing nested property structures.

315stars37forksUpdated 8/1/2026

Security Assessment

Safe(95/100)
Security Score95/100

About unit-test-config-properties

This skill provides patterns for unit testing Spring Boot @ConfigurationProperties classes, focusing on property binding, validation constraints, type conversion, default values, and profile-specific configuration. It addresses the problem of verifying that externalized configuration binds and validates correctly without starting a full Spring application context.

The central technique is ApplicationContextRunner, which loads a properties bean with supplied property values and lets tests assert the resulting bindings. Examples show binding flat and nested properties, verifying defaults when values are omitted, and confirming validation failures via context.hasFailed() for @Validated classes annotated with constraints like @NotBlank, @Min, @Max, and @Positive. Type-conversion tests cover Duration (e.g. 30s), DataSize (e.g. 50MB), comma-delimited lists, and maps. A troubleshooting section guides diagnosis of prefix mismatches (kebab-case to camelCase), missing @Validated annotations, and context-startup failures, and the skill recommends testing edge cases such as empty strings, nulls, and type mismatches.

It targets Java and Spring Boot developers who want fast, reliable coverage of their configuration classes. It suits teams with environment-specific settings and validated configuration who need to catch binding regressions early without slow full-context tests.

FAQ

What is the main testing tool used?

ApplicationContextRunner, which tests property binding and validation without starting the full Spring context.

Can it verify configuration validation?

Yes. It shows testing @Validated properties with constraints like @NotBlank, @Min, @Max, and @Positive, asserting failures with context.hasFailed().

Does it handle type conversions?

Yes. Examples convert Duration, DataSize, comma-delimited lists, and maps from string property values.

How do I test default values?

Bind only a subset of properties and assert that unset fields fall back to their declared defaults.

What dependencies does it need?

spring-boot-starter-test, spring-boot-configuration-processor (provided scope), and AssertJ.

All Files

2 files
SKILL.md9.0 KB
View
references/advanced-examples.md8.7 KB
View

Install unit-test-config-properties

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill