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
  • 相关阅读:
    Ionic3 UI组件之 autocomplete
    Ionic项目中如何使用Native Camera
    AD RMS企业文件版权管理
    利用WSUS部署更新程序
    远程桌面web连接
    文件服务器的管理
    域用户配置文件
    无需转化直接使用ESD映像文件安装系统简明教程
    Windows DHCP备份还原命令
    Bitlocker驱动器加密使用
  • 原文地址:https://www.cnblogs.com/chengjun/p/9067115.html
Copyright © 2011-2022 走看看