julianpeeters / avrohugger

Generate Scala case class definitions from Avro schemas
Apache License 2.0
201 stars 120 forks source link

Generate Scalacheck-Generators and Arbitraries #106

Open diesalbla opened 5 years ago

diesalbla commented 5 years ago

Many Scala projects use Scalacheck for property-based testing. In Scalacheck, to generate test cases one uses a special object or generator, an instance of type Gen[X], which generates values of class X that may cover as many corner cases as possible.

However, building Generators for complex data types, like nested records such as those that avrohugger generates, is a tiresome task. One common way to solve this is to use scalacheck-shapeless, but that is known to increase compile times unreasonably.

Since avrohugger knows how to generate complex case class from basic types, it may as well generate the generators for those. The purpose of this task is to incorporate into Avro-hugger a system to do just that. Since this would introduce a dependency on Scalacheck, we may want to keep this part of the code separate.

julianpeeters commented 5 years ago

This sounds great @diesalbla, thanks for the proposal. I agree this feature should be added.

In regards to where to put it, a separate module sounds does sound nice, however that may prove difficult given avrohugger's current design (specifically, I think an explicit model/intermediate representation would allow a typeclass based approach? It'd be nice to ditch the inheritance. And of course explicit effects would be nice).

In lieu of a refactor, I think the easiest way to add this feature might be to follow the existing pattern and add a field to the Generator constructor, I have in mind a flag that directs the generation of arbitraries in companion objects or a separate file, however I'd be very open to considering alternatives.