ScalaCheck is a well-known library for property-based testing. However, property-based testing is not always possible when side effects are involved, for example when writing an integration test that involves data being stored in a database. When writing non-property-base tests, we often need to initialise some data and then verify some assertions on it. However, manual data generation can make our data biased and preventing us from spotting bugs in our code. Having our data generated randomly not only it would make our test less biased, but it will also make it a lot more readable by highlighting what part of our data are actually relevant in our test.
In this talk we will discuss how to reuse some of the existing ScalaCheck code to generate random instances of given types and how these can be combined to generate random case classes. We will analyse the properties of a ScalaCheck generator and provide examples of how we can manipulate existing generators to meet our needs.
YOU MAY ALSO LIKE:
- Refactor All the Things! (SkillsCast recorded in December 2018)
- Lightbend Akka for Scala - Professional (in London on 11th - 12th November 2019)
- Advanced Scala with Dick Wall (in London on 9th - 11th December 2019)
- F# eXchange 2020 (in London on 2nd - 3rd April 2020)
- The Five Stages of Data: a holistic approach to data analytics and BI (in London on 21st October 2019)
- Code Kata: Yilin Wei - Optics with Monocle (in London on 22nd October 2019)
- Introduction to Markov Chains in F# (SkillsCast recorded in April 2019)
- Initial Algebras for the Uninitiated (SkillsCast recorded in March 2019)
Random Data Generation with ScalaCheck
Daniela Sfregola is a Software Engineer, currently working at Morgan Stanley. She is an active contributor to the Scala Community, as well the maintainer of a few open source projects and organizer of the London Scala User Group meetup. She is writing a book with Manning Publications, titled "Get Programming with Scala".