Unit testing Jakarta Bean Validation constraints and custom validators without Spring context.
Works with
Covers testing built-in constraints ( @NotNull , @Email , @Min , @Max , @Size ) and custom @Constraint implementations with violation assertion patterns
Includes cross-field validation, validation groups for conditional rules, and parameterized test scenarios for multiple inputs
Provides setup patterns using Validation.buildDefaultValidatorFactory().getValidator() and assertion helpers to e
AI-first code editor with Composer
Before installing skills in Cursor, ensure your development environment meets these requirements:
node --versionunit-test-bean-validationExecute the skills CLI command in your project's root directory to begin installation:
Fetches unit-test-bean-validation from giuseppe-trisciuoglio/developer-kit and configures it for Cursor.
The CLI shows a list of agents. Use arrow keys and space to select Cursor:
Confirm successful installation by checking the skill directory location:
Restart Cursor to activate unit-test-bean-validation. Access via /unit-test-bean-validation in your agent's command palette.
We perform automated surface-level scans (Gen AI Scanner, Socket, Snyk) during installation. These checks detect common vulnerabilities but do not guarantee complete security. Always review skill source code and verify the publisher's reputation before production use.
Skills execute code in your environment. Always review source, verify the publisher, and test in isolation before production.
Submit your Claude Code skill and start earning
Automate repetitive workflows and reduce manual effort
Example
Generate reports, summarize documents, draft communications
Save 3-5 hours per week on routine tasks
Learn new skills, understand complex topics, get expert guidance
Example
Explain concepts, provide examples, suggest learning resources
Accelerate learning and skill development by 2x
Enhance output quality through reviews, suggestions, and refinements
Example
Review drafts, suggest improvements, catch errors
Improve work quality by 30-40% with less effort
0
total installs
0
this week
194
GitHub stars
0
upvotes
Run in your terminal
0
installs
0
this week
194
stars
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)<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>
import 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();
}
}
class UserDtoTest extends BaseValidationTest {
@Test
void shouldPassValidationWithValidUser() {
UserDto user = new UserDto("Alice", "[email protected]", 25);
assertThat(validator.validate(user)).isEmpty();
}
@Test
void shouldFailWhenNameIsNull() {
UserDto user = new UserDto(null, "[email protected]", 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", "[email protected]", -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.
Prerequisites
Time Estimate
15-45 minutes depending on use case complexity
Steps
Common Pitfalls
✓ Do
✗ Don't
💡 Pro Tips
✓ Use when
Use when skill capabilities match your task, clear ROI on time saved, and you can validate outputs. Best for repetitive tasks, learning, and quality improvement.
✗ Avoid when
Avoid when task requires deep expertise you can't validate, involves sensitive decisions, or when learning process is more valuable than speed of completion.
giuseppe-trisciuoglio/developer-kit
giuseppe-trisciuoglio/developer-kit
giuseppe-trisciuoglio/developer-kit
giuseppe-trisciuoglio/developer-kit
giuseppe-trisciuoglio/developer-kit
cexll/myclaude
I recommend unit-test-bean-validation for anyone iterating fast on agent tooling; clear intent and a small, reviewable surface area.
unit-test-bean-validation has been reliable in day-to-day use. Documentation quality is above average for community skills.
We added unit-test-bean-validation from the explainx registry; install was straightforward and the SKILL.md answered most questions upfront.
Keeps context tight: unit-test-bean-validation is the kind of skill you can hand to a new teammate without a long onboarding doc.
Registry listing for unit-test-bean-validation matched our evaluation — installs cleanly and behaves as described in the markdown.
unit-test-bean-validation is among the better-maintained entries we tried; worth keeping pinned for repeat workflows.
unit-test-bean-validation reduced setup friction for our internal harness; good balance of opinion and flexibility.
Solid pick for teams standardizing on skills: unit-test-bean-validation is focused, and the summary matches what you get after install.
Useful defaults in unit-test-bean-validation — fewer surprises than typical one-off scripts, and it plays nicely with `npx skills` flows.
Registry listing for unit-test-bean-validation matched our evaluation — installs cleanly and behaves as described in the markdown.
showing 1-10 of 71