{"id":25776480,"url":"https://github.com/instancio/instancio","last_synced_at":"2026-01-11T16:59:20.383Z","repository":{"id":37105606,"uuid":"465599955","full_name":"instancio/instancio","owner":"instancio","description":"A library that creates fully populated objects for your unit tests.","archived":false,"fork":false,"pushed_at":"2025-02-22T05:02:08.000Z","size":10537,"stargazers_count":978,"open_issues_count":4,"forks_count":59,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-02-23T00:38:47.887Z","etag":null,"topics":["data-generator","java","junit","junit-jupiter","random","random-generation","test-automation","test-data-generator","testing","unit-testing"],"latest_commit_sha":null,"homepage":"https://www.instancio.org","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/instancio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"instancio","tidelift":"maven/org.instancio:instancio-core"}},"created_at":"2022-03-03T06:42:29.000Z","updated_at":"2025-02-22T05:02:04.000Z","dependencies_parsed_at":"2023-09-30T07:24:06.355Z","dependency_job_id":"2510a104-b93f-41a9-b7ee-a8b3e995901f","html_url":"https://github.com/instancio/instancio","commit_stats":null,"previous_names":[],"tags_count":88,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/instancio%2Finstancio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/instancio%2Finstancio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/instancio%2Finstancio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/instancio%2Finstancio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/instancio","download_url":"https://codeload.github.com/instancio/instancio/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240987435,"owners_count":19889334,"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","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":["data-generator","java","junit","junit-jupiter","random","random-generation","test-automation","test-data-generator","testing","unit-testing"],"created_at":"2025-02-27T06:01:25.087Z","updated_at":"2026-01-11T16:59:20.376Z","avatar_url":"https://github.com/instancio.png","language":"Java","funding_links":["https://github.com/sponsors/instancio","https://tidelift.com/funding/github/maven/org.instancio:instancio-core","https://tidelift.com/subscription/pkg/maven-org.instancio.instancio-core?utm_source=maven-org.instancio.instancio-core\u0026utm_medium=referral\u0026utm_campaign=enterprise\u0026utm_term=repo"],"categories":["项目","Projects","测试","java"],"sub_categories":["测试","Testing"],"readme":"\u003cimg src=\"https://i.imgur.com/937nevX.png\" alt=\"Instancio\" width=\"250\"/\u003e [![Maven Central](https://img.shields.io/maven-central/v/org.instancio/instancio-core.svg)](https://search.maven.org/artifact/org.instancio/instancio-core/)\n[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=instancio_instancio\u0026metric=alert_status)](https://sonarcloud.io/summary/new_code?id=instancio_instancio)\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=instancio_instancio\u0026metric=coverage)](https://sonarcloud.io/summary/new_code?id=instancio_instancio)\n\n---\n\n# What is it?\n\nInstancio is a Java library that automatically creates and populates objects for your unit tests.\n\nInstead of manually setting up test data:\n\n```java\nAddress address  = new Address();\naddress.setStreet(\"street\");\naddress.setCity(\"city\");\n//...\n\nPerson person = new Person();\nperson.setFirstName(\"first-name\");\nperson.setLastName(\"last-name\");\nperson.setAge(22);\nperson.setGender(Gender.MALE);\nperson.setAddress(address);\n//...\n```\n\nYou can simply do the following:\n\n```java\nPerson person = Instancio.create(Person.class);\n```\n\nThis one-liner returns a fully-populated person, including nested objects and collections.\n\nThe object is populated with random data that can be \u003cb\u003ereproduced\u003c/b\u003e in case of test failure.\n\n### What else can Instancio do?\n\n1. Create collections of objects:\n\n```java\nList\u003cPerson\u003e persons = Instancio.ofList(Person.class).size(10).create();\n```\n\n2. Create streams of objects:\n\n```java\nStream\u003cPerson\u003e persons = Instancio.stream(Person.class).limit(5);\n```\n\n3. Create generic types:\n\n```java\nPair\u003cList\u003cFoo\u003e, List\u003cBar\u003e\u003e pairOfLists = Instancio.create(new TypeToken\u003cPair\u003cList\u003cFoo\u003e, List\u003cBar\u003e\u003e\u003e() {});\n```\n\n4. Customise generated values:\n\n```java\nPerson person = Instancio.of(Person.class)\n    .generate(field(Person::getDateOfBirth), gen -\u003e gen.temporal().localDate().past())\n    .generate(field(Phone::getAreaCode), gen -\u003e gen.oneOf(\"604\", \"778\"))\n    .generate(field(Phone::getNumber), gen -\u003e gen.text().pattern(\"#d#d#d-#d#d-#d#d\"))\n    .subtype(all(AbstractAddress.class), AddressImpl.class)\n    .supply(all(LocalDateTime.class), () -\u003e LocalDateTime.now())\n    .onComplete(all(Person.class), (Person p) -\u003e p.setName(p.getGender() == Gender.MALE ? \"John\" : \"Jane\"))\n    .create();\n```\n\n5. Create reusable templates (Models) of objects:\n\n```java\nModel\u003cPerson\u003e simpsons = Instancio.of(Person.class)\n    .set(field(Person::getLastName), \"Simpson\")\n    .set(field(Address::getCity), \"Springfield\")\n    .generate(field(Person::getAge), gen -\u003e gen.ints().range(40, 50))\n    .toModel();\n\nPerson homer = Instancio.of(simpsons)\n    .set(field(Person::getFirstName), \"Homer\")\n    .create();\n\nPerson marge = Instancio.of(simpsons)\n    .set(field(Person::getFirstName), \"Marge\")\n    .create();\n```\n\n6. Use data feeds for data defined in external sources (e.g. CSV or JSON):\n\n```java\nList\u003cPerson\u003e person = Instancio.ofList(Person.class)\n    .size(10)\n    .applyFeed(all(Person.class), feed -\u003e feed.ofResource(\"persons.csv\"))\n    .create();\n```\n\n7. Define custom feeds for reuse across tests:\n\n```java\n@Feed.Source(resource = \"persons.csv\")\ninterface PersonFeed extends Feed {\n\n  @TemplateSpec(\"${firstName} ${lastName}\")\n  FeedSpec\u003cString\u003e fullName();\n\n  @FunctionSpec(params = {\"fullName\", \"dateOfBirth\"}, provider = BioProvider.class)\n  FeedSpec\u003cString\u003e bio();\n\n  class BioProvider implements FunctionProvider {\n\n    String describePerson(String fullName, LocalDate dateOfBirth) {\n      int age = Period.between(dateOfBirth, LocalDate.now()).getYears();\n      return String.format(\"%s is %d years old\", fullName, age);\n    }\n  }\n}\n\n// Usage:\nList\u003cPerson\u003e person = Instancio.ofList(Person.class)\n    .applyFeed(all(Person.class), feed -\u003e feed.of(PersonFeed.class))\n    .create();\n```\n\n8. Inject arguments into fields and parameters with JUnit 5 ([video tutorial](https://www.youtube.com/watch?v=H8jT43SQis0)):\n\n```java\n@ExtendWith(InstancioExtension.class)\nclass ExampleTest {\n\n    @Given\n    private List\u003cString\u003e randomList;\n\n    @Test\n    void example1(@Given String randomSting, @Given(SomeCustomProvider.class) customString) {\n        //...\n    }\n\n    @ValueSource(strings = {\"foo\", \"bar\"})\n    @ParameterizedTest\n    void example2(String fooOrBar, @Given long randomLong) {\n        // ...\n    }\n}\n```\n\n9. Run parameterized tests against many samples of generated inputs:\n\n```java\n@ExtendWith(InstancioExtension.class)\nclass ExampleTest {\n\n    @InstancioSource(samples = 1000)\n    @ParameterizedTest\n    void example(UUID randomUuid, Foo randomFoo, @Given(BarProvider.class) Bar customBar) {\n        // runs the test method 1000 times against generated inputs\n    }\n}\n```\n\n## Main Features\n\n- Fully reproducible data in case of test failures.\n- Support for generics, `record` and `sealed` classes, Java 21 sequenced collections.\n- Data generation based on JPA and Bean Validation annotations (Hibernate, jakarta).\n- Flexible configuration options and SPIs.\n- Support for defining custom generators.\n- `InstancioExtension` for Junit 5 `@ExtendWith`.\n- Object population via fields and setters.\n\n## Getting Started\n\n- [User guide](https://www.instancio.org/user-guide) (instancio.org)\n- [Javadocs](https://javadoc.io/doc/org.instancio/instancio-core/latest/) (javadoc.io)\n- [Quickstart](https://github.com/instancio/instancio-quickstart) (github.com) sample Maven project with usage examples\n\n  ```sh\n  git clone https://github.com/instancio/instancio-quickstart.git\n  ```\n\n# Maven Coordinates\n\nIf you have JUnit 5 on the classpath, use the `instancio-junit` dependency.\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.instancio\u003c/groupId\u003e\n    \u003cartifactId\u003einstancio-junit\u003c/artifactId\u003e\n    \u003cversion\u003eRELEASE\u003c/version\u003e\n    \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\nTo use Instancio with JUnit 4, TestNG, or standalone, use `instancio-core`:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.instancio\u003c/groupId\u003e\n    \u003cartifactId\u003einstancio-core\u003c/artifactId\u003e\n    \u003cversion\u003eRELEASE\u003c/version\u003e\n    \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\nTo better manage the different dependencies use `instancio-bom`:\n```xml\n\u003cdependencyManagement\u003e\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003eorg.instancio\u003c/groupId\u003e\n            \u003cartifactId\u003einstancio-bom\u003c/artifactId\u003e\n            \u003cversion\u003eRELEASE\u003c/version\u003e\n            \u003ctype\u003epom\u003c/type\u003e\n            \u003cscope\u003eimport\u003c/scope\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n\u003c/dependencyManagement\u003e\n```\n\n\u003e [!CAUTION]\n\u003e The `org.instancio:instancio` artifact on Maven central is an older dependency that should no longer be used.\n\n# Feedback\n\nFeedback and bug reports are greatly appreciated!\n\n- Please submit an [issue](https://github.com/instancio/instancio/issues) for bug reports and feature requests.\n- For general feedback or questions, please create a post in the [Discussions](https://github.com/instancio/instancio/discussions).\n\nPlease check the [User Guide](https://www.instancio.org/user-guide), previous issues and discussions before creating a new one.\n\n# Sponsors\n\nIf you like Instancio, please consider supporting its maintenance and development\nby becoming a [sponsor](https://github.com/sponsors/instancio).\n\nA big thank you to the current project sponsors:\n\n- [@darthblonderss](https://github.com/darthblonderss)\n- [@mauravan](https://github.com/mauravan)\n- [@mevlana14](https://github.com/mevlana14)\n- [@zalabbad](https://github.com/zalabbad)\n\nThanks to [JetBrains](https://jb.gg/OpenSource) and [YourKit](https://www.yourkit.com)\nfor supporting this project with their open source licenses.\n\n\u003cimg src=\"https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.svg\" width=\"150px\" alt=\"JetBrains logo\"\u003e\n\u003cimg src=\"https://www.yourkit.com/images/yklogo.png\" width=\"140px\" alt=\"YourKit logo\"\u003e\n\n## For Enterprise\n\nAvailable as part of the Tidelift Subscription\n\nThe maintainers of Instancio and thousands of other packages are working with Tidelift to deliver commercial\nsupport and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk,\nand improve code health, while paying the maintainers of the exact dependencies you use.\n[Learn more.](https://tidelift.com/subscription/pkg/maven-org.instancio.instancio-core?utm_source=maven-org.instancio.instancio-core\u0026utm_medium=referral\u0026utm_campaign=enterprise\u0026utm_term=repo)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finstancio%2Finstancio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finstancio%2Finstancio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finstancio%2Finstancio/lists"}