zoukankan      html  css  js  c++  java
  • 关于Spring Test 小结

    1.>public class CustomerPackagePrealertControllerTest  extends WebSpringBaseTest{}

    2.>

    @WebAppConfiguration
    public class WebSpringBaseTest extends SpringBaseTest {

    }

    3.>

    //@RunWith(SpringJUnit4ClassRunner.class)
    //@RunWith(SpringJUnit4ClassRunner.class) // SpringJUnit支持,由此引入Spring-Test框架支持!
    @RunWith(SpringRunner.class)
    @SpringBootTest(classes = OrderCustomerServiceApplication.class)
    //@WebAppConfiguration
    //@Configuration
    //@ContextConfiguration({"/application-context.xml"})
    //@SpringBootTest
    //@WebAppConfiguration // 由于是Web项目,Junit需要模拟ServletContext,因此我们需要给我们的测试类加上@WebAppConfiguration。
    @Transactional
    //@TransactionConfiguration(defaultRollback = true)
    @Rollback(false)
    public class SpringBaseTest extends BaseTest implements ApplicationContextAware {}

    注意:

    较新版的Spring Boot取消了@SpringApplicationConfiguration这个注解,用@SpringBootTest就可以了

    使用的test包的版本号要与spring的一致,避免jar包依赖冲突

    直接用注解

    @RunWith(SpringRunner.class)
    @SpringBootTest

    @SpringApplicationConfiguration 注解在1.4就被替换了,新版本这个注解已经不能用了

    SpringJunit支持,需要引入Spring-Test框架
    Web项目,Junit需要模拟ServletContext,因此需要给测试类上加上@WebAppConfiguration
  • 相关阅读:
    appium工作原理
    Python文件读写模式
    Redis info 参数详解
    MySQL show status 参数详解
    Monit : 开源监控工具介绍
    Ansible(三)
    Ansible(二)
    Ansible(一)
    使用python实现后台系统的JWT认证(转)
    微信公众号-5秒内不回复测试并处理方案,顺便复习php 时间执行
  • 原文地址:https://www.cnblogs.com/chengjun/p/9067115.html
Copyright © 2011-2022 走看看