- Home
- Skills
- Giuseppe Trisciuoglio
- Developer Kit
- Unit Test Config Properties
unit-test-config-properties_skill
- Python
99
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill giuseppe-trisciuoglio/developer-kit --skill unit-test-config-properties- SKILL.md14.8 KB
Overview
This skill provides concise, battle-tested patterns for unit testing Spring @ConfigurationProperties classes using ApplicationContextRunner and @ConfigurationPropertiesTest techniques. It helps validate property binding, type conversion, nested structures, defaults, validation constraints, and profile-specific wiring without starting a full Spring context. Use it to keep configuration tests fast, focused, and reliable.
How this skill works
The patterns use ApplicationContextRunner to bootstrap minimal contexts with explicit property values and beans, then assert bound properties or context failures. Tests cover simple bindings, nested objects and collections, type conversions (Duration, DataSize, Charset), validation via @Validated, default-value behavior, and profile-specific user configurations. Failures are asserted by checking context.hasFailed() and inspecting the failure message when relevant.
When to use it
- Verify @ConfigurationProperties binding and prefixes without loading the full application
- Assert type conversions for Duration, DataSize, lists, maps, and enums
- Validate @Validated constraints (@NotBlank, @Min, @Max, @Email, @Positive) on config classes
- Test nested properties, lists of sub-objects, and default values
- Confirm profile-specific beans or settings load correctly in prod/dev scenarios
Best practices
- Use ApplicationContextRunner.withPropertyValues(...) and .withBean(...) to isolate tests
- Cover all property paths including nested fields and indexed list entries
- Assert both success and failure cases for validation constraints
- Test default values by not providing properties and then by overriding them
- Include edge cases: empty strings, nulls, type mismatches and missing required props
- Keep tests focused and fast — each runner instance should validate one scenario
Example use cases
- Bind and assert security settings (jwtSecret, expiration, two-factor flag) from properties
- Validate server configuration fails when host is blank or port is out of range
- Verify nested database pool settings and a list of replica entries bind correctly
- Confirm Duration and DataSize strings convert to Java types as expected
- Load dev vs prod configuration via spring.profiles.active and verify bean values
FAQ
Provide invalid property values via ApplicationContextRunner.withPropertyValues(...). Run the context and assert context.hasFailed() and that the failure message contains the violated field name.
Can I test @ConstructorBinding classes with these patterns?
Yes, but ensure all constructor parameters are bindable. Use ApplicationContextRunner with the @ConfigurationProperties bean and supply all required properties in tests.