I would like to know if a fake data generator exists for Java. In Perl exists Data::Faker
and there's a port to Ruby called faker
, for JavaScript faker.js
. Someone know about a fake data generator for Java, that can provide random names, phone number, P.O. box number, etc...
Asked
Active
Viewed 4.3k times
48

Brian Tompsett - 汤莱恩
- 5,753
- 72
- 57
- 129

Rubens Mariuzzo
- 28,358
- 27
- 121
- 148
-
1I've never seen something like this (in the libraries java is shipping with). Maybe there is a 3rd party library that does that for you in Java. In this case you should use a search engine to find out :) – Thomas Jungblut Jun 15 '11 at 19:25
-
Checkout [ThinkUI](http://www.thinkui.com/datagen/index.html) – Bala R Jun 15 '11 at 19:29
-
I've recently authored a library that can pass as faker-like: https://github.com/nomemory/mockneat – Andrei Ciobanu Aug 22 '17 at 11:13
-
You could try [Datafaker](https://www.datafaker.net), a JVM library to generate fake data. It's an up to date version (Disclaimer: maintained by me). – Erik Pragt Feb 01 '22 at 12:44
4 Answers
51
Try jFairy. This is new project in early stage.
Fairy fairy = Fairy.create();
Person person = fairy.person();
System.out.println(person.fullName()); // Chloe Barker
System.out.println(person.email()); // barker@yahoo.com
System.out.println(person.telephoneNumber()); // 690-950-802
Company company = fairy.company();
System.out.println(company.name()); // Robuten Associates
System.out.println(company.url()); // http://www.robuteniaassociates.com
Person salesman = fairy.person(withCompany(company));
System.out.println(salesman.fullName()); // Juan Camacho
System.out.println(salesman.companyEmail()); // juan.camacho@robuteniaassociates.com
PS. I'm a contributor.

Nicolas Filotto
- 43,537
- 11
- 94
- 122

MariuszS
- 30,646
- 12
- 114
- 155
-
2We are working on adding more functionalities right now and a new version will be released soon. – OlgaMaciaszek Feb 10 '15 at 12:12
-
1How can i become a contributor too? im using it but it doesnt fit with my real life project. To be clear, it's language based, not locale based (lets say Kanada with french), or whatever you want. Language based is not fitting to a real life project. A phoneNumber is not based on language but on locale. I like the base concept and think its the best open thing by now, but its not fitting with the reality in a big project. By now i just modify the objects per reflection to fit, but i think i can provide something which is more usable. On githu i can not see how i can contribute. – Henning Luther May 08 '16 at 17:37
-
Any help is always welcome. To contribute use Pull Requests, more to read: https://guides.github.com/activities/contributing-to-open-source/ – MariuszS May 08 '16 at 18:17
-
How to create test data which can start with word of my choice like "Test Chloe Barker" – Saif Siddiqui May 18 '21 at 12:37
16
http://www.andygibson.net/blog/article/generate-test-data-with-datafactory/ How to use:
Add it in your
pom.xml
<dependency> <groupId>org.fluttercode.datafactory</groupId> <artifactId>datafactory</artifactId> <version>0.8</version> <type>jar</type> </dependency>
Test it...
public class Main { public static void main(String[] args) { DataFactory df = new DataFactory(); for (int i = 0; i < 100; i++) { String name = df.getFirstName() + " "+ df.getLastName(); System.out.println(name); } } }
Output :
Lindsey Craft
Erica Larsen
Ryan Levine
Erika Smith
Brooklyn Sloan
Karen Mayer
Eddie O'neill
Nancy Stevens
-
2
-
Also check this: https://dzone.com/articles/generate-test-data-datafactory – akhil_mittal Sep 05 '15 at 11:28
-
15
There is a Java port of the Perl Data::Faker - java-faker

Dmytro Chyzhykov
- 1,814
- 1
- 20
- 17
-
It's worth to use, indeed. In my opinion it's got a good l10n support. – Dmytro Chyzhykov Nov 06 '12 at 21:28
-
2I recently used `java-faker`, and creating an instance of `Faker` thrown a NPE. I proceeded to report an issue for this: http://github.com/DiUS/java-faker/issues/6 – Rubens Mariuzzo Apr 08 '13 at 14:52
-
Most of built in faker-s are useless. Because there are plenty of them (pokemon, startrek etc) its hard to find useful one. – Krzysztof Aug 06 '21 at 16:56
7

Tony the Pony
- 40,327
- 71
- 187
- 281
-
3HibernateMock is no more:-( But has been reborn as http://code.google.com/p/jpamock/ – enkor Mar 09 '12 at 14:42
-
i tried Benerator.. it seems to be a good project ... but there is little or no gratis support on it.. activiy on this project is very low – arthur Jul 28 '12 at 01:20