简体   繁体   中英

How h2 works in springboot test cases

I am using springboot and H2 database for test cases.

I have multiple test classes each annotated with @SpringBootTest. Each class has multiple test methods annotated with @Test

My doubt is, will h2 database be cleared

  1. after each test method(annotated with @Test) execution or
  2. after each test class(annotated with @SpringBootTest) execution or
  3. after running all the test cases present in the application.

If case1 is true, then need to load the data to database in the @Before method which will be executed before each test method?

If case2 is true, then need to load the data to db in the @BeforeClass method which will be executed before each class execution.

If case3 is true, then if i load all the data to db in a test case, how to make it run first before all other test cases run.

What is the appropriate place to load the data to database?

Thanks in advance.

database-rider could be useful for initializing your H2 database with data before each test case. See https://github.com/database-rider/database-rider

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