unit-test-mapper-converter_skill

This skill provides patterns for unit testing mappers and converters to verify accurate data transformations between DTOs and domain objects.
  • 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-mapper-converter

  • SKILL.md12.9 KB

Overview

This skill provides practical, focused patterns for unit testing mappers and converters (MapStruct and custom converters). It helps validate field mapping, null handling, nested transformations, enum mappings, type conversions, bidirectional consistency, and partial updates in isolation. Use it to catch mapping defects early without spinning up integration layers.

How this skill works

The skill describes concrete unit-test patterns: obtain mapper instances with Mappers.getMapper() for standalone tests, assert field-level mappings, and use recursive comparison for nested structures. It covers tests for nulls, enums, custom expressions, type converters, round-trip mapping, and partial updates using @MappingTarget. Examples use JUnit 5 and AssertJ and include Maven/Gradle setup notes.

When to use it

  • When verifying MapStruct-generated mappers in unit tests
  • When testing custom converter classes (date/time, formatting, parsing)
  • When validating nested object and collection transformations
  • When confirming null handling and null-aware mapping strategies
  • When checking enum/value mapping and custom expression logic
  • Before integration tests to ensure mapping correctness in isolation

Best practices

  • Test every public mapper method and both directions where applicable
  • Use Mappers.getMapper() for non-Spring standalone tests to avoid DI complexity
  • Assert null and edge cases (null inputs, empty collections, invalid formats) explicitly
  • Use assertThat().usingRecursiveComparison() for complex nested objects
  • Write focused tests for custom expressions and converters to isolate logic
  • Keep tests deterministic: avoid relying on generated code side effects or runtime environment

Example use cases

  • Unit test that entity→DTO mapping maps each field and nested address correctly
  • Verify DTO→entity reverse mapping preserves values in a round-trip test
  • Test custom date formatter parse/format methods and invalid input handling
  • Validate @ValueMapping enum translations between domain and DTO enums
  • Check updateEntity(@MappingTarget) only changes intended fields and respects null-aware strategies
  • Test list mapping and collection immutability behavior for mapped collections

FAQ

No. Use Mappers.getMapper(Class) for standalone unit tests. Use Spring only when testing componentModel = "spring" beans in integration tests.

How do I test nested mappers referenced by a parent mapper?

Instantiate the top-level mapper via Mappers.getMapper or inject mocks for nested mappers. Use recursive comparison to assert nested fields or test nested mappers independently.

What should I assert for partial updates?

Assert that fields present in the DTO are updated, and fields absent or null are preserved according to your nullValuePropertyMappingStrategy.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
unit-test-mapper-converter skill by giuseppe-trisciuoglio/developer-kit | VeilStrat