classpath — or an array of annotated classes that is used to configure the application. These locations or classes are the same as or similar to those specified l or other configuration files for production deployments.
By default, once loaded, the configured ApplicationContext is reused for each test. Thus, the setup cost is incurred only once per test suite, and subsequent test execution is much faster. In this context, the term “test suite” means all tests run in the same JVM — for example, all tests run from an Ant, Maven, or Gradle build for a given project or module. In the unlikely case that a test corrupts the application context and requires reloading (for example, by modifying a bean definition or the state of an application object) the TestContext framework can be configured to reload the configuration and rebuild the application context before executing the next test.
See Context Management and Context Caching with the TestContext framework.
Spring TestContext Framework包含spring ApplicationContext实例和WebApplicationContext实例的加载,同时还包括了上下⽂的缓存。对加载上下⽂的缓存⽀持是⼗分重要的,因为启动的时间可以变为issue级别,当然这不是因为覆盖整个spring本⾝,⽽是因为spring的IoC 容器对对象的实例化是要消耗时间的。例如⼀个项⽬包含50到100个Hibernater映射⽂件可能需要消耗10到20秒来加载映射⽂件,并
且需要注意的是,在运⾏每⼀个测试⽤了之前的代价导致导致减慢所有的测试⽤例的运⾏,这将降低开发⼈员的⽣产⼒。
3.2.2 提供测试⽬标实例的依赖注⼊
3.2.3 为集成测试提供事务管理
3.2.4 为开发者在编写集成测试⽤例是提供spring特性的基础类
3.3 JDBC测试⽀持
未完待续......
3.4 注解
未完待续......
3.5 Spring TestContext Framework
未完待续......
3.6 Spring MVC Test Framework
Spring MVC Test framework通过适⽤于JUnit、TestNG或者其他测试框架的流式api,为测试Spring MVC的代码提供了⽀持. 这是基于 spring-test模块的 Servlet API mock objects ,因此不需要运⾏Servlet容器。它使⽤DispatcherServlet 提供完整的Spring MVC运⾏时⾏为,并且在standalone模式的基础上,通过TestContext framework 为加载实际的Spring 配置提供⽀持,standalone模式中controllers能够⼿动实例化并且每次只测试⼀个。
Spring MVC Test 也为测试 RestTemplate的代码提供客户端的⽀持。客户端测试mock了server端的相应,并且不需要运⾏服务端。
Spring Boot 提供了⼀个完整的运⾏server的端到端集成测试的选项。如果你也有相同的诉求,请移步到 Spring Boot reference page。了解更多的关于out-of-container 和end-to-end integration 测试, 详见 Differences between Out-of-Container and End-to-End Integration Tests.
3.6.1. Server-Side Tests
spring ioc注解

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。