DEV Community

namuan
namuan

Posted on • Originally published at deskriders.dev

1 1

Using EasyRandom with Spring Framework

Tired of creating objects in tests. Try using EasyRandom library. Here is how easily you can add it to a Spring Java project

Step 1: Add gradle/maven dependency

https://mvnrepository.com/artifact/org.jeasy/easy-random

Step 2: Declare it in test

Step 3: Use it to generate random data objects

Step 4: 😍

Tips:

Random initial seed

In the default setup, EasyRandom uses a default seed value to generate randam data.
Although it is quite simple to initiate EasyRandom with a random seed.

Enforcing javax.validation rules:

If an object is using javax.validation then there is an extension which enforces those rules when generating random objects.

Include https://github.com/j-easy/easy-random/wiki/bean-validation-support


Github: https://github.com/namuan/dev-rider-codesnippets/tree/master/spring-boot-snippets

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

While many AI coding tools operate as simple command-response systems, Qodo Gen 1.0 represents the next generation: autonomous, multi-step problem-solving agents that work alongside you.

Read full post

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay