Spring Boot @IntegrationTest注释用于测试


v-star*위위
2025-03-26 07:59:39 (6天前)
  1. 我很新


SpringBoot
</跨度>
。我需要了解如何使用编写集成测试

SpringBoot
</跨度>
。我在互联网上看到过一些使用@IntegrationTest注释的例子,而有些则是

3 条回复
  1. 0# 求赞有赞必回 | 2019-08-31 10-32





    IntegrationTest

    已被弃用的正弦弹簧启动1.4,所以建议使用

    SpringBootTest

    1.4之后




    从1.4开始,不赞成使用webEnvironment = RANDOM_PORT或webEnvironment = DEFINED_PORT的org.springframework.boot.test.context.SpringBootTest。



  2. 1# 浮华丶 | 2019-08-31 10-32



    在springboot中编写集成测试的基本模板。
    sql组是附加注释。当你想要在方法运行之前和之后执行特定的sql查询时,你可以使用@SqlGroup注释。




    1. @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”)})

    2. public class CustomerControllerIntTest {}

    3. </code>

登录 后才能参与评论