unit-test-bean-validation

Validate JavaBean constraint violations and custom validators with JUnit 5.

Updated Apr 5, 2026
One-click install
npx skills add https://github.com/rizaldiem/digital-invitation-web_V2 --skill unit-test-bean-validation-rizaldiem
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unit-test-bean-validation
Source: https://github.com/rizaldiem/digital-invitation-web_V2/tree/main/.windsurf/skills/unit-test-bean-validation
Command: npx skills add https://github.com/rizaldiem/digital-invitation-web_V2 --skill unit-test-bean-validation-rizaldiem

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides clear patterns to verify Jakarta Bean Validation annotations and custom Constraint validators at the unit-test level so validation logic is correct without booting a Spring context or hitting the database.

Core Features & Use Cases

  • Validator setup: Guidance to instantiate a Validator and perform isolated validation with Validation.buildDefaultValidatorFactory().
  • Constraint testing: Examples for asserting built-in constraints (@NotNull, @Email, @Min/@Max, @Size) and extracting property path, message, and invalid value.
  • Custom and cross-field validators: Patterns for testing custom ConstraintValidator implementations, multi-field constraints (e.g., password match), validation groups, and parameterized invalid inputs.
  • Use Case: Validate DTOs and service input objects to ensure data integrity, verify custom phone-number or password-match rules, and confirm localized messages and groups behave as expected.

Quick Start

Instantiate a Validator via the Validation factory and write focused JUnit 5 tests that assert ConstraintViolation property paths, messages, and invalid values for your DTOs and custom validators.

Frequently Asked Questions about unit-test-bean-validation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I unit test Jakarta Bean Validation constraints without starting a Spring context?

Unit test Jakarta Bean Validation constraints without a Spring context by instantiating a Validator via Validation.buildDefaultValidatorFactory() and asserting ConstraintViolation property paths, messages, and invalid values directly in JUnit 5 tests.

What is the best way to test custom ConstraintValidator implementations in JUnit 5?

The best way to test custom ConstraintValidator implementations in JUnit 5 is to invoke validation using a default Validator factory and assert ConstraintViolation details for parameterized invalid inputs against expected property paths and messages.

How do I assert ConstraintViolation property paths and messages for Hibernate Validator?

Assert ConstraintViolation property paths and messages for Hibernate Validator by calling validate on your DTO, iterating the returned violations, and matching extracted property paths and localized messages against expected values in your JUnit 5 test.

Can I test validation groups and cross-field constraints without a Spring context?

Yes, you can test validation groups and cross-field constraints without a Spring context by passing the target group class to the Validator validate method and asserting ConstraintViolation outputs for multi-field rules like password matching.

Does unit testing Jakarta Bean Validation require Hibernate Validator on the test classpath?

Unit testing Jakarta Bean Validation requires Hibernate Validator on the test classpath as the provider implementation for Validation.buildDefaultValidatorFactory to function correctly and execute built-in and custom constraint checks.