Closed levibostian closed 2 years ago
At this time, I like to generate fakes from code instead of JSON file reading. JSON file reading is convenient because it's easy to keep up-to-date and does not require annoying up keep of a Fakes enum, but it lacks features such as saying randomFile
to get randomly generated objects. Random is better then static for testing.
Could use Sourcery for this.
Iterate properties of a struct and generate code that says, "id: String.random" as the type. I can then create extensions and objects to make sure all data types (String, Int, Bool, custom types) all resolve.
This would only work for random. If I want to create realistic instances I would need to manually create these objects. That's ok because those cases are more rare.
Let's say we have a struct:
And we create a fake generator for testing:
To make it more convenient to generate these in tests...
I would prefer this to make it more convenient to generate fakes.