naver / fixture-monkey

Let Fixture Monkey generate test instances including edge cases automatically
https://naver.github.io/fixture-monkey
Apache License 2.0
555 stars 88 forks source link

Add a new module supports datafaker #525

Open seongahjo opened 1 year ago

seongahjo commented 1 year ago

Describe the feature you request

Add a new module supports datafaker

armandino commented 1 year ago

I believe java-faker is no longer maintained. There is an actively maintained forked at https://github.com/datafaker-net/datafaker

@bodiam - maybe somebody from the Data Faker team can help with the integration?

bodiam commented 1 year ago

Hi there! This library looks interesting, and happy to share some ideas on this.

Is there some api or idea you had in mind?

seongahjo commented 1 year ago

@bodiam Hi thank you for your help! We would discuss how to integrate with datafaker in a weekly meeting and share ideas on this issue.

Thank you for your help too, @armandino

armandino commented 1 year ago

@seongahjo no worries. Happy to connect two great libraries.

seongahjo commented 1 year ago

@bodiam Hello, we've discussed how to integrate with datafaker.

Is there any way to make a random value which satisfies condition? For example, we want to make a firstName whose length is 5.

It would be helpful with this feature.

bodiam commented 1 year ago

@seongahjo given the nature of the fake values, that would be hard. For example, how would we create a country of 30 characters long? We don't really know the limits even, since they are depending on the Locales.

Yes, it's possible to generate a random string of X characters, but that defeats the purpose of the library.

Can I ask why you'd need such a feature?

seongahjo commented 1 year ago

@bodiam We are supporting Jakarta Bean Validation annotations when generating an object.

If a String field has a @Size annotation, the length of field would be a given value.

For example.

class Foo{
   @Size(3)
   String Bar;
}

A length of Bar always be 3.

We'd like to use datafaker to generate a feasible String field value inferred by a property name or other condition. The field might have Jakarta Bean Validation annotations. It would be helpful if datafaker supports filtering by length for an above reason.

bodiam commented 1 year ago

It's tricky I think. Some of these fields are populated by regular expressions, or concatenations of different fields.

This might be a silly idea, but how about invoking the faker, potentially several times (100s of times shouldn't be an issue), and record the shortest/longest lengths?

DaraFaker cannot, and will never be able to generate a string of arbitrary length for any propery. For example, a license plate of 25 characters wouldn't make sense, or a full name of 2 characters.