In a previous article I described how to load test data that your ScalaTest Play Framework functional tests might need using Play Framework’s Evolutions. This made use of the SimpleEvolutionsReader class and defining evolutions in the test setup code.
Recently I wanted to also load some test data from a file and so turned to the ClassLoaderEvolutionsReader class which loads resources from the class path.
The trouble was I wanted to apply the schema from my standard evolution files first and then load the test data. The ClassLoaderEvolutionsReader requires evolutions revisions to start at 1 which would conflict with the standard application evolutions already applied.
So I wrote a custom SingleRevisionClassLoaderEvolutionsReader that reads a single revision from the class path.
https://gist.github.com/davidkeen/df83d5716bb72073df4fb5834f727d2d
You can then place your evolution files in /test/resources/evolutions/default/ and apply them after your standard evolutions in your test setup, for example, if your test data was in a file called 100.sql :
// Load the database schema Evolutions.applyEvolutions(db) // Load the test data Evolutions.applyEvolutions(db, SingleRevisionClassLoaderEvolutionsReader(revision = 100))