Install any skill in seconds. Free to start, no credit card required.
Get Started Free →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.
.claude/skills/giuseppe-trisciuoglio-unit-test-bean-validation/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-02 | ✗→✓ | ▲ Improved | 48% | 0% |
| case-06 | ✗→✓ | ▲ Improved | 76% | 0% |
| case-13 | ✗→✓ | ▲ Improved | 76% | 0% |
| case-16 | ✗→✓ | ▲ Improved | 28% | 0% |
| case-19 | ✓→✗ | ▼ Worse | 58% | 0% |
This skill provides executable patterns for unit testing Jakarta Bean Validation annotations and custom validators using JUnit 5. Covers built-in constraints (@NotNull, @Email, @Min, @Max, @Size), custom @Constraint implementations, cross-field validation, and validation groups. Tests run in isolation without Spring context.
@Constraint validators and constraint violation messagesjakarta.validation-api and hibernate-validator in test scopeValidator once in @BeforeEach using Validation.buildDefaultValidatorFactory()getPropertyPath(), getMessage(), getInvalidValue()references/custom-validators.md for patterns@ParameterizedTestreferences/advanced-patterns.md)xml<dependency> <groupId>jakarta.validation</groupId> <artifactId>jakarta.validation-api</artifactId> </dependency> <dependency> <groupId>org.hibernate.validator</groupId> <artifactId>hibernate-validator</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <scope>test</scope> </dependency>
javaimport jakarta.validation.*; import jakarta.validation.ConstraintViolation; import jakarta.validation.path.Path; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.*; class BaseValidationTest { protected Validator validator; @BeforeEach void setUpValidator() { validator = Validation.buildDefaultValidatorFactory().getValidator(); } }
javaclass UserDtoTest extends BaseValidationTest { @Test void shouldPassValidationWithValidUser() { UserDto user = new UserDto("Alice", "alice@example.com", 25); assertThat(validator.validate(user)).isEmpty(); } @Test void shouldFailWhenNameIsNull() { UserDto user = new UserDto(null, "alice@example.com", 25); assertThat(validator.validate(user)) .extracting(ConstraintViolation::getMessage) .contains("must not be blank"); } @Test void shouldFailWhenEmailIsInvalid() { UserDto user = new UserDto("Alice", "invalid-email", 25); Set<ConstraintViolation<UserDto>> violations = validator.validate(user); assertThat(violations) .extracting(ConstraintViolation::getPropertyPath) .extracting(Path::toString) .contains("email"); } @Test void shouldFailWhenAgeIsBelowMinimum() { UserDto user = new UserDto("Alice", "alice@example.com", -1); assertThat(validator.validate(user)) .extracting(ConstraintViolation::getMessage) .contains("must be greater than or equal to 0"); } @Test void shouldFailWhenMultipleConstraintsViolated() { UserDto user = new UserDto(null, "invalid", -5); assertThat(validator.validate(user)).hasSize(3); } }
For custom constraint patterns, see references/custom-validators.md:
@Constraint annotationsConstraintValidatorFor validation groups and parameterized tests, see references/advanced-patterns.md:
groups parameter@ParameterizedTest with @ValueSource and @CsvSourceBaseValidationTest to share validator setup@NotNull for mandatory fields combined with other constraints@NotNull with other constraints for mandatory fieldsValidator instances are thread-safe and can be shared@Valid on nested objects for recursive validationtrue for null valuesValidatorFactory not found: Ensure jakarta.validation-api and hibernate-validator are on test classpath.
Custom validator not invoked: Verify @Constraint(validatedBy = YourValidator.class) annotation is correct.
Null values pass validation: This is expected behavior — constraints ignore null unless @NotNull is present.
Wrong violation count: Use hasSize() to verify exact count, check all fields in the object.
Property path incorrect: Ensure the field, not the getter, has the constraint annotation.
references/custom-validators.mdreferences/advanced-patterns.md| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-03 | pass→pass | 10,114 | 11,282 | +12% | 1 | 1 | 0% | 1,917 | 3,718 | +94% | 0 | 0 | — |
case-01 | fail→fail | 15,340 | 15,759 | +3% | 1 | 1 | 0% | 3,360 | 5,030 | +50% | 0 | 0 | — |
case-02 | fail→pass | 11,519 | 9,293 | -19% | 1 | 1 | 0% | 2,275 | 3,361 | +48% | 0 | 0 | — |
case-04 | pass→pass | 12,108 | 14,328 | +18% | 1 | 1 | 0% | 2,324 | 4,333 | +86% | 0 | 0 | — |
case-05 | pass→pass | 27,849 | 13,383 | -52% | 1 | 1 | 0% | 2,668 | 4,214 | +58% | 0 | 0 | — |
case-06 | fail→pass | 8,562 | 19,637 | +129% | 1 | 1 | 0% | 1,702 | 2,997 | +76% | 0 | 0 | — |
case-07 | pass→pass | 10,768 | 11,788 | +9% | 1 | 1 | 0% | 2,075 | 3,473 | +67% | 0 | 0 | — |
case-08 | pass→pass | 10,978 | 6,738 | -39% | 1 | 1 | 0% | 2,060 | 2,832 | +37% | 0 | 0 | — |
case-09 | pass→pass | 6,852 | 10,425 | +52% | 1 | 1 | 0% | 1,316 | 2,549 | +94% | 0 | 0 | — |
case-10 | pass→pass | 11,924 | 8,125 | -32% | 1 | 1 | 0% | 2,118 | 2,897 | +37% | 0 | 0 | — |
case-11 | pass→pass | 11,139 | 8,033 | -28% | 1 | 1 | 0% | 2,229 | 3,146 | +41% | 0 | 0 | — |
case-12 | fail→fail | 14,650 | 17,158 | +17% | 1 | 1 | 0% | 2,615 | 3,390 | +30% | 0 | 0 | — |
case-13 | fail→pass | 12,493 | 6,210 | -50% | 1 | 1 | 0% | 1,504 | 2,649 | +76% | 0 | 0 | — |
case-14 | pass→pass | 9,105 | 11,135 | +22% | 1 | 1 | 0% | 1,673 | 3,739 | +123% | 0 | 0 | — |
case-15 | pass→pass | 8,852 | 7,588 | -14% | 1 | 1 | 0% | 1,726 | 2,913 | +69% | 0 | 0 | — |
case-16 | fail→pass | 11,124 | 4,829 | -57% | 1 | 1 | 0% | 1,851 | 2,377 | +28% | 0 | 0 | — |
case-17 | pass→pass | 9,684 | 7,625 | -21% | 1 | 1 | 0% | 1,978 | 3,114 | +57% | 0 | 0 | — |
case-18 | pass→pass | 12,645 | 9,997 | -21% | 1 | 1 | 0% | 2,033 | 3,157 | +55% | 0 | 0 | — |
case-19 | pass→fail | 12,123 | 9,761 | -19% | 1 | 1 | 0% | 2,082 | 3,282 | +58% | 0 | 0 | — |
case-20 | pass→pass | 11,943 | 14,412 | +21% | 1 | 1 | 0% | 2,308 | 4,355 | +89% | 0 | 0 | — |
case-21 | pass→pass | 8,397 | 5,579 | -34% | 1 | 1 | 0% | 1,644 | 2,690 | +64% | 0 | 0 | — |
case-22 | pass→pass | 14,453 | 6,419 | -56% | 1 | 1 | 0% | 2,107 | 2,613 | +24% | 0 | 0 | — |
case-23 | pass→pass | 27,542 | 10,259 | -63% | 1 | 1 | 0% | 2,624 | 3,352 | +28% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted. The headline lift of +13 percentage points is the difference between those two pass rates over the 23 comparable cases. 1 case got worse with the skill loaded, and it is included in that figure.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.