Fixtures is a fancy word for sample data. Fixtures allow you to populate your testing database with predefined data before your tests run.
The
fixture implementation for loading testdata in play 1 was great. But all fixture related code for play 2 I
found was ebean releated. After some research I decided to use
Fixy for loading test data. It needed only some small changes to adapt it for play 2.
I added the code as a module to
play4jpa. To use it, just copy the module to your project and add the necessary config to your
Build.scala.
A yaml fixture file in the play conf folder can be loaded inside a transaction with this code:
Fixy fixtures = new JpaFixyBuilder(JPA.em()).build();
fixtures.load("myFixture.yaml");
The yaml for a Task Model with a name an done flag would look like this:
- !package models
- Task(task1):
name: Task 1
done: false
Check out the
samples in the fixy unit tests on github for more details on using fixy.
fixture, fixtures, fixy, JPA, Play Framework, Play4JPA, yaml
You may also like
I just changed the url of this blog to https://jensjaeger.com. TLS encryption is now the default for all request to this page. It might be possible that some image links on some articles are hard coded http. If you find such an error it would be nice if you leave me comment so i can
Read More
Prettytime is a nice java library to format a java Date()s in a nice humanized ago format, like: moments ago 2 minutes ago 13 hours ago 7 months ago 2 years ago Prettytime is localized in over 30 languages. It’s super simple to use Add the dependency to your maven pom: org.ocpsoft.prettytime prettytime 3.2.7.Final or
Read More