{"id":20093017,"url":"https://github.com/qala-io/datagen","last_synced_at":"2025-05-06T04:31:58.756Z","repository":{"id":145202907,"uuid":"58282625","full_name":"qala-io/datagen","owner":"qala-io","description":"Java lib that generates random data (numbers, strings, dates) - mostly to facilitate Randomized Testing.","archived":false,"fork":false,"pushed_at":"2023-11-29T22:50:17.000Z","size":242,"stargazers_count":58,"open_issues_count":4,"forks_count":4,"subscribers_count":7,"default_branch":"master","last_synced_at":"2023-11-29T23:35:25.599Z","etag":null,"topics":["java","random","random-data-generation","random-generation","random-number-generators","randomization","testing"],"latest_commit_sha":null,"homepage":"http://qala.io/blog/randomized-testing.html","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/qala-io.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2016-05-07T20:11:51.000Z","updated_at":"2023-11-29T22:50:15.000Z","dependencies_parsed_at":"2023-11-29T23:43:33.216Z","dependency_job_id":null,"html_url":"https://github.com/qala-io/datagen","commit_stats":null,"previous_names":[],"tags_count":20,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qala-io%2Fdatagen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qala-io%2Fdatagen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qala-io%2Fdatagen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qala-io%2Fdatagen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qala-io","download_url":"https://codeload.github.com/qala-io/datagen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224489731,"owners_count":17319963,"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":["java","random","random-data-generation","random-generation","random-number-generators","randomization","testing"],"created_at":"2024-11-13T16:45:33.727Z","updated_at":"2024-11-13T16:45:34.306Z","avatar_url":"https://github.com/qala-io.png","language":"Java","funding_links":[],"categories":["测试"],"sub_categories":[],"readme":"Datagen\n-------\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.qala.datagen/qala-datagen/badge.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22io.qala.datagen%22)\n\nJava library to generate random data (numbers, strings, dates) - to facilitate \n[Randomized Testing](http://qala.io/blog/randomized-testing.html). Randomization may be used to improve coverage, but\nit can also speed up the process of writing \u0026 running tests. Some use cases for randomization:\n\n* [Combinatorial Testing](./examples/combinatorial.md) - helps reducing the number of test cases you need \nto write and run\n* [Fighting with Unique Constraints](./examples/unique-constraints.md) - do you have a test that registers users with\nunique username? And the next time you run the test it fails because such user already exists..\n* [\"Wow, I didn't know about that\"](./examples/wow-i-did-not-know-that.md) effect - sometimes randomization\nmay discover tricky cases that you couldn't think of.\n* [Which one to pick?](./examples/which-one-to-pick.md) - often when choosing test data there is no clear winner\nof what value to pick. Randomization helps with that and ensures we're not prone to Pesticides Effect. \n\n## Example\n\n```java\nimport java.time.OffsetDateTime;\n\nimport static io.qala.datagen.RandomDate.beforeNow;\nimport static io.qala.datagen.RandomShortApi.*;\n\npublic class Dog {\n    private String name;\n    private OffsetDateTime timeOfBirth;\n    private double weight;\n    private double height;\n\n    public static Dog random() {\n        Dog dog = new Dog();\n        dog.name = alphanumeric(1, 100);\n        dog.timeOfBirth = nullOr(beforeNow().offsetDateTime());\n        dog.weight = positiveDouble();\n        dog.height = positiveInteger();\n        return dog;\n    }\n}\n```\n\n## [JUnit5 Integration](./junit5/README.md)\n\n```java\n@Alphanumeric(min = 2, max = 29, name = \"middle value\")\n@Alphanumeric(length = 30, name = \"max boundary\")\n@English(max=30)\nvoid eachAnnotationInvokesTheTestOnceAndPassesParameters(String value, String name) {\n    assertTrue(value.length() \u003e= 1 \u0026\u0026 value.length() \u003c= 31, \"Failed case: \" + name);\n}\n\n@RandomInt(min = 1, name = \"greater than zero\")\n@RandomInt(max = -1, name = \"less than zero\")\nvoid zeroInt_isNotPassed(int param, String name) {\n    assertNotEquals(0, param, \"Failed case: \" + name);\n}\n```\n\n## Strings\n\n```java\nimport static io.qala.datagen.RandomValue.*;\nimport static io.qala.datagen.StringModifier.Impls.*;\nimport static io.qala.datagen.RandomShortApi.*;\n```\n\n| Flexible API                                             | Short API            | Result\n|----------------------------------------------------------|----------------------|--------\n| `length(10).english()`                                   |`english(10)`         | `\"DcRZUNPrED\"`\n| `between(1, 10).alphanumeric()`                          |`alphanumeric(0, 10)` | `\"zG9G\"`\n| `between(1, 10).numeric()`                               |`numeric(1, 10)`      | `\"7167162\"`\n| `length(5).unicode()`                                    |`unicode(5)`          | `\"䂞ꂣ뢧䯺婜\"`\n| `length(5).string(\"A_ B\")`                               |                      | `\" _B B\"`\n| `length(10).with(specialSymbol()).english()`             |                      | `\"hOzKEV#iWv\"`\n| `length(10).with(oneOf(\"_,\")).english()`                 |                      | `\"dwei,cNTfW\"`\n| `length(5).with(spaces()).numeric()`                     |                      | `\"874 9 \"`\n| `length(3).with(spaceLeft()).english()`                  |                      | `\" mT\"`\n| `length(4).with(spacesRight(2)).english()`               |                      | `\"hF  \"`\n| `length(10).with(prefix(\"BLAH\")).numeric()`              |                      | `\"BLAH453677\"`\n| `between(1, 10).alphanumerics(4)`                        |                      | `[\"cvA\", \"mTMDj0\", \"N\", \"\"]`\n|                                                          | `mixedCase(\"blah\")`  | `\"bLaH\"`\n\n## Nulls \u0026 Blanks\n\n|       API            | Result\n|----------------------|------------------------\n| `nullOrEmpty()`      | `\"\"`, `null`\n| `nullOrBlank()`      | `\"\"`, `\"  \"`, `null`\n| `nullOr(10L)`        | `null`, `10L`\n| `nullOr(\"string\")`   | `null`, `\"string\"`\n| `blankOr(\"string\")`  | `\"\"`, `\"  \"`, `null`, `\"string\"`\n\n## Repeats\n\n```java\nimport static io.qala.datagen.RandomString.Type.*;\nimport static io.qala.datagen.RandomValue.*;\nimport static io.qala.datagen.Repeater.*;\n\nrepeat(length(4), NUMERIC).string(\"-\").times(4)`\n```\n\nResult: `\"9338-8349-6940-7714\"`\n\n## Numbers\n\n```java\nimport static io.qala.datagen.RandomValue.*;\nimport static io.qala.datagen.RandomShortApi.*;\n```\n\n|Flexible API                                             | Short API            | Result\n|---------------------------------------------------------|----------------------|--------\n|`between(0, 100).integer()`                              | `integer(100)`       | `89`\n|`between(-100, 100).integer()`                           | `integer(-100, 100)` | `-19`\n|                                                         | `positiveInteger()`  | `3432145`\n|                                                         | `Long()`             | `7635811362052252913`\n|                                                         | `negativeDouble()`   | `-8.9946257128846746E18`\n\n## Collections/Arrays\n\n```java\nimport static io.qala.datagen.RandomElements.*;\nimport static io.qala.datagen.RandomShortApi.*;\n```\n\n|Flexible API                                             | Short API                              | Result\n|---------------------------------------------------------|----------------------------------------|--------\n|`from(\"A\", \"B\", \"C\", \"D\").sample()`                      | `sample(\"A\", \"B\", \"C\")`                | `\"C\"`\n|`from(\"A\", \"B\", \"C\", \"D\").sample(2)`                     | `sampleMultiple(2, \"A\", \"B\", \"C\")`     | `[\"B\", \"A\"]`\n|`from(\"A\", \"B\").sampleWithReplacement(3)`                |                                        | `[\"A\", \"A\", \"B\"]`\n|`from(\"A\", \"B\", \"C\").shuffled()`                         | `shuffled(\"A\", \"B\", \"C\")`              | `[\"C\", \"A\", \"B\"]`\n\n## Java Date\n\n```java\nimport static io.qala.datagen.RandomValue.*;\n\nSimpleDateFormat f = new SimpleDateFormat(\"yyyy-MM-dd\");\nbetween(f.parse(\"2015-01-01\"), f.parse(\"2016-01-01\")).date();\n```\n\nResult: `2015-11-30T08:33:20.349`\n\n## Java8 DateTime\n\n```java\n// Requires Java8 and qala-datagen-java8types dependency\nimport static io.qala.datagen.RandomDate.*;\n```\n\nAPI                                                | Result\n---------------------------------------------------|--------\n`plusMinus100Years().zonedDateTime()`              | `1937-09-27T01:16:15.925440485+01:00[Europe/Belgrade]`\n`since(yearAgo()).instant()`                       | `2015-11-30T08:39:28.397051483Z`\n`before(now()).instant()`                          | `-241279778-02-14T16:07:18.061693370Z`\n`between(yearsAgo(2), startOfMonth()).localDate()` | `2014-09-30`\n\n## Booleans\n\n```java\nimport static io.qala.datagen.RandomShortApi.*;\n```\n\nAPI                                                | Result\n---------------------------------------------------|--------\n`bool()` or `weighedTrue(0.5)`                     | `false`\n`bools(4)`                                         | `[false, true, true, false]`\n`nullableBool()`                                   | `Boolean.TRUE`\n\n## Functions (for Java8 lambdas)\n\n```java\nimport static io.qala.datagen.RandomShortApi.*;\nPerson person = new Person();\n\ncallOneOf(() -\u003e person.firstName = english(5),\n          () -\u003e person.lastName = english(5));\n```\n\nResult: `Person[null, \"PDGRq\"]`\n\n```java\ncallNoneOrMore(() -\u003e person.firstName = english(5),\n               () -\u003e person.lastName = english(5));\n```\n\nResult: `Person[null, null]`\n\n```\ncallOneOrMore(() -\u003e person.firstName = english(5),\n              () -\u003e person.lastName = english(5));\n```\n\nResult: `Person[\"LjxYh\", \"UXoBt\"]`\n\n## Other\n\n- [Maven Central coordinates](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22io.qala.datagen%22)\n- Occasional updates are posted in [Twitter](https://twitter.com/Qala_io)\n- [Our blog](http://qala.io/blog.html)\n\n## Special thanks\n\nTo keep the lib tiny and get rid of extra dependencies (there are no \ntransitive dependencies) some of the code was borrowed from these libs:\nCommons Lang, Commons Math. Hail to open source!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqala-io%2Fdatagen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqala-io%2Fdatagen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqala-io%2Fdatagen/lists"}