该 IntegrationTest 已被弃用的正弦弹簧启动1.4,所以建议使用 SpringBootTest 1.4之后
IntegrationTest
SpringBootTest
从1.4开始,不赞成使用webEnvironment = RANDOM_PORT或webEnvironment = DEFINED_PORT的org.springframework.boot.test.context.SpringBootTest。
在springboot中编写集成测试的基本模板。 sql组是附加注释。当你想要在方法运行之前和之后执行特定的sql查询时,你可以使用@SqlGroup注释。
@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = MainApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @SqlGroup({ @Sql(executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:beforeTestRun.sql"), @Sql(executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, scripts = "classpath:afterTestRun.sql")}) public class CustomerControllerIntTest {}