How to re-create database before each test in Spring?

后端 未结 9 2142
盖世英雄少女心
盖世英雄少女心 2020-12-07 16:30

My Spring-Boot-Mvc-Web application has the following database configuration in application.properties file:

spring.datasource.url=jdbc:h2:tcp://         


        
9条回答
  •  时光说笑
    2020-12-07 17:16

    Actually, I think you want this:

    @DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
    

    http://docs.spring.io/autorepo/docs/spring-framework/4.2.6.RELEASE/javadoc-api/org/springframework/test/annotation/DirtiesContext.html

    @DirtiesContext may be used as a class-level and method-level annotation within the same class. In such scenarios, the ApplicationContext will be marked as dirty after any such annotated method as well as after the entire class. If the DirtiesContext.ClassMode is set to AFTER_EACH_TEST_METHOD, the context will be marked dirty after each test method in the class.

提交回复
热议问题