Does a fake data generator exists in Java? [closed]

浪子不回头ぞ 提交于 2019-12-31 08:02:43

问题


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:

  1. Add it in your pom.xml

    <dependency>
        <groupId>org.fluttercode.datafactory</groupId>
        <artifactId>datafactory</artifactId>
        <version>0.8</version>
        <type>jar</type>
    </dependency>
    
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!