Whenever I run Automated Tests on开发者_运维技巧 my site, all the tables get cleaned to 0 rows. Is that by design? How do I prevent them?
Update: Found the real 'culprit' %test.jpa.ddl=create
That is by design. Unit tests should not have any external dependencies on some pre-existing state such as persisted data. If you need data for testing purposes, you need to set that up in your @Before
setup method. For example:
@Before
public void setUp() {
// The following loads test data from the YAML file
Fixtures.loadModels("test-data/users.yml");
}
@Test
public void someTest() {
assertEquals(5, User.count()); // 5 User records exist due to @Before method
}
You should take a look at your conf/application.conf file and notice that you have a line that reads:
%test.db=mem
This is the default setting - which says that when the application is run in test mode, use an in-memory database. If you want your tests to work on persisted data (not recommended), you can change the test mode db settings. See Play test documentation for details.
I had the same problem until I updated application.conf file:
%test.jpa.ddl=none
https://playframework.com/documentation/1.2.4/configuration#jpa
精彩评论