简体   繁体   中英

Grails 3 integration test - data loading

Grails version : 3.3.5

I am porting a legacy web app to latest grails. There are 500+ integration tests. Each integration test method needs to load complex data in the database before the test begins and clean it up at the end. Data loading and later the test code should run in one transaction for the test code to be able to see the loaded data. I tried using spock run listener for data loading. Unfortunately, application context or dataSource is not loaded when beforeSpec and beforeFeature methods run. Please suggest best way to implement this. Can someone give an idea of which grails/spock classes are involved in loading the tests and executing them? Any help or hint is highly appreciated. Thanks.

As far as I have understood from the question, below are couple of things you may try.

  • Can load Database data in Bootstrap for test environment only if all the tests somewhat share the same data.
  • Try @RunOnce and @Before on a method to load data before running any fixture method.
  • Have a look at build-test-data plugin.

The documentation may help too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM