{"id":19347076,"url":"https://github.com/dvgaba/easy-random","last_synced_at":"2025-11-09T02:03:10.223Z","repository":{"id":52751585,"uuid":"517766692","full_name":"dvgaba/easy-random","owner":"dvgaba","description":"The simple, stupid random Java beans/records generator","archived":false,"fork":false,"pushed_at":"2025-02-23T04:33:06.000Z","size":3390,"stargazers_count":16,"open_issues_count":3,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-12T06:48:20.863Z","etag":null,"topics":["java","java-random","java-records","jdk16","junit","protobuf","random-data-generation","testing"],"latest_commit_sha":null,"homepage":"https://github.com/j-easy/easy-random/wiki","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dvgaba.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-07-25T17:50:39.000Z","updated_at":"2025-04-09T10:22:06.000Z","dependencies_parsed_at":"2025-01-10T18:32:49.738Z","dependency_job_id":"d2ed77c6-ced4-4668-9a52-4bcd5f758525","html_url":"https://github.com/dvgaba/easy-random","commit_stats":null,"previous_names":[],"tags_count":30,"template":false,"template_full_name":null,"purl":"pkg:github/dvgaba/easy-random","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvgaba%2Feasy-random","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvgaba%2Feasy-random/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvgaba%2Feasy-random/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvgaba%2Feasy-random/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dvgaba","download_url":"https://codeload.github.com/dvgaba/easy-random/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dvgaba%2Feasy-random/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":283447139,"owners_count":26837401,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-09T02:00:05.828Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","java-random","java-records","jdk16","junit","protobuf","random-data-generation","testing"],"created_at":"2024-11-10T04:13:49.383Z","updated_at":"2025-11-09T02:03:05.210Z","avatar_url":"https://github.com/dvgaba.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"***\n\n\u003cdiv align=\"center\"\u003e\n    \u003cb\u003e\u003cem\u003eEasy Random\u003c/em\u003e\u003c/b\u003e\u003cbr\u003e\n    The simple, stupid random Java\u0026trade; beans generator\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](http://opensource.org/licenses/MIT)\n[![Build Status](https://github.com/dvgaba/easy-random/actions/workflows/maven.yml/badge.svg)](https://github.com/dvgaba/easy-random/actions/workflows/maven.yml)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.dvgaba/easy-random-core/badge.svg?style=flat)](https://repo1.maven.org/maven2/io/github/dvgaba/easy-random-core/6.1.1/)\n[![Javadocs](https://www.javadoc.io/badge/io.github.dvgaba/easy-random-core.svg)](https://www.javadoc.io/doc/io.github.dvgaba/easy-random-core)\n[![Project status](https://img.shields.io/badge/Project%20status-active-darkgreen.svg)](https://img.shields.io/badge/Project%20status-active-darkgreen.svg)\n\n\u003c/div\u003e\n\n***\n\n## Project status\n\nActive\n\n## Latest news\n* 2/22/2025 7.1.1 Minor release, made library compatible with Android, Thanks @[Marian Jureczko ](https://github.com/mjureczko).\n* 10/23/2024 7.1.0 Minor release, added support for sealed classes, Thanks @[Marian Jureczko ](https://github.com/mjureczko). Some minor 3PP updates.\n* 1/15/2024 7.0.0 Major release, default Java version bumped to 17 and other 3PP version bump. [Breaking changes].\n* 9/1/2023 6.2.1 Minor release to initialize leaf nodes for Records [Breaking change].  \n* 8/10/2023 6.2.0 Minor release to add custom radomizer support for protobuf, 3PP and code refactoring.  \n* 5/23/2023 6.1.8 Patch release to fix [#26](https://github.com/dvgaba/easy-random/issues/26) and [#28](https://github.com/dvgaba/easy-random/issues/28), thanks @[carborgar](https://github.com/carborgar).\n* 5/12/2023 6.1.7 Patch release to improve record support, thanks @[mjureczko](https://github.com/mjureczko) and minor 3PP fixes.\n* 3/19/2023 6.1.5 Patch release to bump protobuf-java and snakeyaml and fix bug preventing custom randomizers on Record Types. Thanks [carborgar](https://github.com/carborgar)\n* 3/12/2023 6.1.3 Patch release to fix bug preventing Collections field population\n* 10/29/2022 6.1.2 Patch release to bump protobuf version to vulnerability\n* 9/23/2022 6.1.1 Added support to generate random protobuf data, this is based on [murdos/easy-random-protobuf](https://github.com/murdos/easy-random-protobuf)\n* 8/10/2022 Added a fork with JDK 11 support [easy-random-jdk11](https://github.com/dvgaba/easy-random-jdk11) package is available in maven centeral. \n* 8/3/2022: Added support to JDK 16 and Java Record and minor bug fixes\n* 15/11/2020: Easy Random v5.0.0 is out and is now based on Java 11. Feature wise, this release is the same as v4.3.0. Please check the [release notes](https://github.com/j-easy/easy-random/releases/tag/easy-random-5.0.0) for more details.\n* 07/11/2020: Easy Random v4.3.0 is now released with support for generic types and fluent setters! You can find all details in the [change log](https://github.com/j-easy/easy-random/releases/tag/easy-random-4.3.0).\n\n# What is Easy Random ?\n\nEasy Random is a library that generates random Java beans. You can think of it as an [ObjectMother](https://martinfowler.com/bliki/ObjectMother.html) for the JVM. Let's say you have a class `Person` and you want to generate a random instance of it, here we go:\n\n```java\nEasyRandom easyRandom = new EasyRandom();\nPerson person = easyRandom.nextObject(Person.class);\n```\n\nThe method `EasyRandom#nextObject` is able to generate random instances of any given type.\n\n# What is this EasyRandom API ?\n\nThe `java.util.Random` API provides 7 methods to generate random data: `nextInt()`, `nextLong()`, `nextDouble()`, `nextFloat()`, `nextBytes()`, `nextBoolean()` and `nextGaussian()`.\nWhat if you need to generate a random `String`? Or say a random instance of your domain object?\nEasy Random provides the `EasyRandom` API that extends `java.util.Random` with a method called `nextObject(Class type)`.\nThis method is able to generate a random instance of any arbitrary Java bean.\n\nThe `EasyRandomParameters` class is the main entry point to configure `EasyRandom` instances. It allows you to set all\nparameters to control how random data is generated:\n\n```java\nEasyRandomParameters parameters = new EasyRandomParameters()\n   .seed(123L)\n   .objectPoolSize(100)\n   .randomizationDepth(3)\n   .charset(forName(\"UTF-8\"))\n   .timeRange(nine, five)\n   .dateRange(today, tomorrow)\n   .stringLengthRange(5, 50)\n   .collectionSizeRange(1, 10)\n   .scanClasspathForConcreteTypes(true)\n   .overrideDefaultInitialization(false)\n   .ignoreRandomizationErrors(true);\n\nEasyRandom easyRandom = new EasyRandom(parameters);\n```\n\nFor more details about these parameters, please refer to the [configuration parameters](https://github.com/j-easy/easy-random/wiki/Randomization-parameters) section.\n\nIn most cases, default options are enough and you can use the default constructor of `EasyRandom`.\n\nEasy Random allows you to control how to generate random data through the [`org.jeasy.random.api.Randomizer`](https://github.com/j-easy/easy-random/blob/master/easy-random-core/src/main/java/org/jeasy/random/api/Randomizer.java) interface and makes it easy to exclude some fields from the object graph using a `java.util.function.Predicate`:\n\n```java\nEasyRandomParameters parameters = new EasyRandomParameters()\n   .randomize(String.class, () -\u003e \"foo\")\n   .excludeField(named(\"age\").and(ofType(Integer.class)).and(inClass(Person.class)));\n\nEasyRandom easyRandom = new EasyRandom(parameters);\nPerson person = easyRandom.nextObject(Person.class);\n```\n\nIn the previous example, Easy Random will:\n\n* Set all fields of type `String` to `foo` (using the `Randomizer` defined as a lambda expression)\n* Exclude the field named `age` of type `Integer` in class `Person`.\n\nThe static methods `named`, `ofType` and `inClass` are defined in [`org.jeasy.random.FieldPredicates`](https://github.com/j-easy/easy-random/blob/master/easy-random-core/src/main/java/org/jeasy/random/FieldPredicates.java) \nwhich provides common predicates you can use in combination to define exactly which fields to exclude.\nA similar class called [`TypePredicates`](https://github.com/j-easy/easy-random/blob/master/easy-random-core/src/main/java/org/jeasy/random/TypePredicates.java) can be used to define which types to exclude from the object graph.\nYou can of course use your own `java.util.function.Predicate` in combination with those predefined predicates. \n\n#Easy Random for Protobuf\neasy-random-protobuf module provides support for generating random data for protobuf message objects. \nFor full support for easy-random capabilities it is advised to rely on \n```java\nProtoEasyRandom easyRanom  = new ProtoEasyRandom();\n```\n\n\n# Why Easy Random ?\n\nPopulating a Java object with random data can look easy at first glance, unless your domain model involves many related classes. In the previous example, let's suppose the `Person` type is defined as follows:\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/wiki/j-easy/easy-random/images/person.png\"\u003e\n\u003c/p\u003e\n\n**Without** Easy Random, you would write the following code in order to create an instance of the `Person` class:\n\n```java\nStreet street = new Street(12, (byte) 1, \"Oxford street\");\nAddress address = new Address(street, \"123456\", \"London\", \"United Kingdom\");\nPerson person = new Person(\"Foo\", \"Bar\", \"foo.bar@gmail.com\", Gender.MALE, address);\n```\n\nAnd if these classes do not provide constructors with parameters (may be some legacy beans you can't change), you would write:\n\n```java\nStreet street = new Street();\nstreet.setNumber(12);\nstreet.setType((byte) 1);\nstreet.setName(\"Oxford street\");\n\nAddress address = new Address();\naddress.setStreet(street);\naddress.setZipCode(\"123456\");\naddress.setCity(\"London\");\naddress.setCountry(\"United Kingdom\");\n\nPerson person = new Person();\nperson.setFirstName(\"Foo\");\nperson.setLastName(\"Bar\");\nperson.setEmail(\"foo.bar@gmail.com\");\nperson.setGender(Gender.MALE);\nperson.setAddress(address);\n```\n\n**With** Easy Random, generating a random `Person` object is done with `new EasyRandom().nextObject(Person.class)`.\nThe library will **recursively** populate all the object graph. That's a big difference!\n\n## How can this be useful ?\n\nSometimes, the test fixture does not really matter to the test logic. For example, if we want to test the result of a new sorting algorithm, we can generate random input data and assert the output is sorted, regardless of the data itself:\n\n```java\n@org.junit.Test\npublic void testSortAlgorithm() {\n\n   // Given\n   int[] ints = easyRandom.nextObject(int[].class);\n\n   // When\n   int[] sortedInts = myAwesomeSortAlgo.sort(ints);\n\n   // Then\n   assertThat(sortedInts).isSorted(); // fake assertion\n\n}\n```\n\nAnother example is testing the persistence of a domain object, we can generate a random domain object, persist it and assert the database contains the same values:\n\n```java\n@org.junit.Test\npublic void testPersistPerson() throws Exception {\n   // Given\n   Person person = easyRandom.nextObject(Person.class);\n\n   // When\n   personDao.persist(person);\n\n   // Then\n   assertThat(\"person_table\").column(\"name\").value().isEqualTo(person.getName()); // assretj db\n}\n```\n\nThere are many other uses cases where Easy Random can be useful, you can find a non exhaustive list in the [wiki](https://github.com/j-easy/easy-random/wiki/use-cases).\n\n## Extensions\n\n* [JUnit extension](https://glytching.github.io/junit-extensions/randomBeans): Use Easy Random to generate random data in JUnit tests (courtesy of [glytching](https://github.com/glytching))\n* [Vavr extension](https://github.com/xShadov/easy-random-vavr-extension): This extension adds support to randomize [Vavr](https://github.com/vavr-io/vavr) types (courtesy of [xShadov](https://github.com/xShadov))\n* [Protocol Buffers extension](https://github.com/murdos/easy-random-protobuf): This extension adds support to randomize [Protocol Buffers](https://developers.google.com/protocol-buffers) generated types (courtesy of [murdos](https://github.com/murdos))\n\n## Articles and blog posts\n\n* [Easy testing with ObjectMothers and EasyRandom](https://www.jworks.io/easy-testing-with-objectmothers-and-easyrandom/)\n* [Quick Guide to EasyRandom in Java](https://www.baeldung.com/java-easy-random)\n* [Top secrets of the efficient test data preparation](https://waverleysoftware.com/blog/test-data-preparation/)\n* [Random Data Generators for API Testing in Java](https://techblog.dotdash.com/random-data-generators-for-api-testing-in-java-369c99075208)\n* [EasyRandom 4.0 Released](https://www.jworks.io/easyrandom-4-0-released/)\n* [Type Erasure Revisited](https://www.beyondjava.net/type-erasure-revisited)\n* [Generate Random Test Data With jPopulator](https://www.beyondjava.net/newsflash-generate-random-test-data-jpopulator)\n\n## Who is using Easy Random ?\n\n* [Netflix](https://github.com/Netflix/AWSObjectMapper/blob/v1.11.723/build.gradle#L71)\n* [JetBrains](https://github.com/JetBrains/intellij-community/blob/201.6073/plugins/gradle/tooling-extension-impl/testSources/org/jetbrains/plugins/gradle/tooling/serialization/ToolingSerializerTest.kt#L8)\n* [Mulesoft](https://github.com/mulesoft/mule-wsc-connector/blob/1.5.6/src/test/java/org/mule/extension/ws/ConfigEqualsTestCase.java#L14)\n* [Easy Cucumber](https://github.com/osvaldjr/easy-cucumber/blob/0.0.18/pom.xml#L122)\n* [Open Network Automation Platform](https://github.com/onap/vid/blob/6.0.3/vid-app-common/src/test/java/org/onap/vid/controller/MsoControllerTest.java#L43)\n\n## Contribution\n\nYou are welcome to contribute to the project with pull requests on GitHub.\nPlease note that Easy Random is in [maintenance mode](https://github.com/j-easy/easy-random#project-status),\nwhich means only pull requests for bug fixes will be considered.\n\nIf you believe you found a bug or have any question, please use the [issue tracker](https://github.com/j-easy/easy-random/issues).\n\n## Core team and contributors\n\n#### Core team\n\n* [Mahmoud Ben Hassine](https://github.com/benas)\n* [Pascal Schumacher](https://github.com/PascalSchumacher)\n\n#### Awesome contributors\n\n* [Adriano Machado](https://github.com/ammachado)\n* [Alberto Lagna](https://github.com/alagna)\n* [Andrew Neal](https://github.com/aeneal)\n* [Aurélien Mino](https://github.com/murdos)\n* [Arne Zelasko](https://github.com/arnzel)\n* [dadiyang](https://github.com/dadiyang)\n* [Dovid Kopel](https://github.com/dovidkopel)\n* [Eric Taix](https://github.com/eric-taix)\n* [euZebe](https://github.com/euzebe)\n* [Fred Eckertson](https://github.com/feckertson)\n* [huningd](https://github.com/huningd)\n* [Johan Kindgren](https://github.com/johkin)\n* [Joren Inghelbrecht](https://github.com/joinghel)\n* [Jose Manuel Prieto](https://github.com/prietopa)\n* [kermit-the-frog](https://github.com/kermit-the-frog)\n* [Lucas Andersson](https://github.com/LucasAndersson)\n* [Michael Düsterhus](https://github.com/reitzmichnicht)\n* [Nikola Milivojevic](https://github.com/dziga)\n* [nrenzoni](https://github.com/nrenzoni)\n* [Oleksandr Shcherbyna](https://github.com/sansherbina)\n* [Petromir Dzhunev](https://github.com/petromir)\n* [Rebecca McQuary](https://github.com/rmcquary)\n* [Rémi Alvergnat](http://www.pragmasphere.com)\n* [Rodrigue Alcazar](https://github.com/rodriguealcazar)\n* [Ryan Dunckel](https://github.com/sparty02)\n* [Sam Van Overmeire](https://github.com/VanOvermeire)\n* [Valters Vingolds](https://github.com/valters)\n* [Vincent Potucek](https://github.com/punkratz312)\n* [Weronika Redlarska](https://github.com/weronika-redlarska)\n* [Konstantin Lutovich](https://github.com/lutovich)\n* [Steven_Van_Ophem](https://github.com/stevenvanophem)\n* [Jean-Michel Leclercq](https://github.com/LeJeanbono)\n* [Marian Jureczko](https://github.com/mjureczko)\n* [Unconditional One](https://github.com/unconditional)\n* [JJ1216](https://github.com/JJ1216)\n* [Sergey Chernov](https://github.com/seregamorph)\n\nThank you all for your contributions!\n\n## License\n\nThe [MIT License](http://opensource.org/licenses/MIT). See [LICENSE.txt](https://github.com/j-easy/easy-random/blob/master/LICENSE.txt).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvgaba%2Feasy-random","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdvgaba%2Feasy-random","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdvgaba%2Feasy-random/lists"}