Java中是否存在假数据生成器?[已关闭]

2022-08-31 22:26:52

我想知道Java是否存在伪造的数据生成器。在Perl中存在,并且有一个名为faker的Ruby端口,用于JavaScript。有人知道Java的假数据生成器,它可以提供随机名称,电话号码,邮政信箱号码等...Data::Fakerfaker.js


答案 1

试试jFairy。这是处于早期阶段的新项目。

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. 我是贡献者。


答案 2

http://www.andygibson.net/blog/article/generate-test-data-with-datafactory/如何使用:

  1. 将其添加到您的pom.xml

    <dependency>
        <groupId>org.fluttercode.datafactory</groupId>
        <artifactId>datafactory</artifactId>
        <version>0.8</version>
        <type>jar</type>
    </dependency>
    
  2. 测试它...

    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);
        }
      }
     }
    

输出:

Lindsey Craft
Erica Larsen
Ryan Levine
Erika Smith
Brooklyn Sloan
Karen Mayer
Eddie O'neill
Nancy Stevens

推荐