unit-test-bean-validation
Provides patterns for unit testing Jakarta Bean Validation (JSR-380), including @Valid, @NotNull, @Min, @Max, @Email constraints with Hibernate Validator. Generates custom validator tests, constraint violation assertions, validation groups, and parameterized validation tests. Validates data integrity logic without Spring context. Use when writing validation tests, bean validation tests, or testing custom constraint validators.
Security Assessment
About unit-test-bean-validation
This skill provides comprehensive patterns and executable code examples for unit testing Jakarta Bean Validation (JSR-380) constraints in Java applications. It focuses on testing validation logic in isolation without requiring Spring Boot context, making tests faster and more focused. The skill covers testing built-in validation annotations like @NotNull, @Email, @Min, @Max, and @Size, as well as custom constraint validators and complex validation scenarios.
The skill's main features include setting up the Hibernate Validator test infrastructure, writing assertions for constraint violations, testing custom @Constraint implementations, implementing cross-field validation tests (such as password matching), and using validation groups for conditional validation rules. It provides practical Maven dependency configurations, base test class patterns with proper Validator initialization, and comprehensive examples using JUnit 5 and AssertJ for fluent assertions. The skill emphasizes testing both valid and invalid cases, extracting violation details like property paths and messages, and using parameterized tests for efficient coverage of multiple input scenarios.
This skill is ideal for Java developers working with Jakarta Bean Validation in enterprise applications, particularly those building REST APIs with DTOs that require data integrity validation. It's valuable for developers who need to write thorough unit tests for validation logic without the overhead of integration tests, QA engineers implementing validation test suites, and teams adopting test-driven development practices for data validation. The skill is particularly useful when validating complex business rules, ensuring data integrity at the application boundary, or migrating from javax.validation to jakarta.validation.
FAQ
What dependencies are required to use this skill?
You need jakarta.validation-api for the validation interfaces, hibernate-validator as the implementation (in test scope), and optionally assertj-core for fluent assertions. These are typically added to your Maven or Gradle configuration.
Can I use this skill with Spring Boot applications?
Yes, this skill focuses on unit testing validation logic in isolation without Spring context, making tests faster. However, the same validation annotations work within Spring Boot applications. For integration testing with Spring's validation infrastructure, you would use @SpringBootTest instead.
How do I test custom constraint validators?
The skill references custom validator patterns in the documentation. You create a Validator instance using Validation.buildDefaultValidatorFactory().getValidator(), apply it to objects with your custom constraints, and assert on the resulting ConstraintViolation set to verify property paths, messages, and invalid values.
What's the difference between testing with and without validation groups?
Validation groups allow conditional validation based on context. Without groups, all constraints are validated. With groups, you can validate only specific subsets of constraints by passing group classes to validator.validate(object, Group.class), enabling scenario-specific validation rules.
Does this work with the older javax.validation (JSR-303/349)?
This skill specifically targets Jakarta Bean Validation (JSR-380), which is the modern standard after the Java EE to Jakarta EE transition. The patterns are similar to javax.validation, but package names differ (jakarta.validation vs javax.validation).
Install unit-test-bean-validation
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
giuseppe-trisciuoglio/developer-kit