问题
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...
回答1:
If you're using Hibernate, try HibernateMock.
Also:
ThinkUI
Benerator
回答2:
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.
回答3:
There is a Java port of the Perl Data::Faker - java-faker
回答4:
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
来源:https://stackoverflow.com/questions/6362683/does-a-fake-data-generator-exists-in-java