Scala or Java equivalent of Ruby factory_girl or Python factory_boy (convenient factory pattern for unit testing)

There is a project called Fixture-Factory(https://github.com/six2six/fixture-factory). It was based in the Factory-Girl's idea.

You could easily create your object's template definition:

Fixture.of(Client.class).addTemplate("valid", new Rule(){{
  add("id", random(Long.class, range(1L, 200L)));
  add("name", random("Anderson Parra", "Arthur Hirata"));
  add("nickname", random("nerd", "geek"));
  add("email", "${nickname}@gmail.com");
  add("birthday", instant("18 years ago"));
  add("address", one(Address.class, "valid"));
}});

And then you can easily use it in your tests:
Client client = Fixture.from(Client.class).gimme("valid");


I created a new java framework Factory Duke to provide the same feature as Factory_Girl https://github.com/regis-leray/factory_duke

Really easy to use, define a template (in this case the default)

FactoryDuke.define(User.class, u -> {
    u.setLastName("Scott");
    u.setName("Malcom");
    u.setRole(model.Role.USER);
});

And use it

User user = FactoryDuke.build(User.class);

Please read the document to see advanced features