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...
-
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 JungblutJun 15, 2011 at 19:25
-
Checkout ThinkUI– Bala RJun 15, 2011 at 19:29
-
I've recently authored a library that can pass as faker-like: github.com/nomemory/mockneat– Andrei CiobanuAug 22, 2017 at 11:13
-
You could try Datafaker, a JVM library to generate fake data. It's an up to date version (Disclaimer: maintained by me).– Erik PragtFeb 1, 2022 at 12:44
Add a comment
|
4 Answers
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.
-
2We are working on adding more functionalities right now and a new version will be released soon. Feb 10, 2015 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. May 8, 2016 at 17:37
-
Any help is always welcome. To contribute use Pull Requests, more to read: guides.github.com/activities/contributing-to-open-source– MariuszSMay 8, 2016 at 18:17
-
How to create test data which can start with word of my choice like "Test Chloe Barker" May 18, 2021 at 12:37
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: dzone.com/articles/generate-test-data-datafactory Sep 5, 2015 at 11:28
-
There is a Java port of the Perl Data::Faker - java-faker
-
It's worth to use, indeed. In my opinion it's got a good l10n support. Nov 6, 2012 at 21:28
-
2I recently used
java-faker
, and creating an instance ofFaker
thrown a NPE. I proceeded to report an issue for this: github.com/DiUS/java-faker/issues/6 Apr 8, 2013 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. Aug 6, 2021 at 16:56
-
3HibernateMock is no more:-( But has been reborn as code.google.com/p/jpamock– enkorMar 9, 2012 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– arthurJul 28, 2012 at 1:20