我想知道Java是否存在伪数据生成器。在Perl中存在Data::Faker
,并且有一个名为faker
的Ruby端口,用于JavaScript faker.js
。有人知道Java的伪数据生成器,它可以提供随机名称,电话号码,P.O。箱号等...
答案 0 :(得分:47)
试试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。我是贡献者。
答案 1 :(得分:15)
Perl Data :: Faker有一个Java端口 - java-faker
答案 2 :(得分:14)
http://www.andygibson.net/blog/article/generate-test-data-with-datafactory/ 使用方法:
将其添加到pom.xml
<dependency>
<groupId>org.fluttercode.datafactory</groupId>
<artifactId>datafactory</artifactId>
<version>0.8</version>
<type>jar</type>
</dependency>
测试它......
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
答案 3 :(得分:8)