原创 Spring、Spring Boot和TestNG測試指南 - 測試AOP 原

碼雲地址 Spring提供了一套AOP工具,但是當你把各種Aspect寫完之後,如何確定這些Aspect都正確的應用到目標Bean上了呢?本章將舉例說明如何對Spring AOP做測試。 首先先來看我們事先定義的Bean以及Aspect。

原创 Spring、Spring Boot和TestNG測試指南 - 測試@Configuration 原 薦

碼雲地址 在Spring引入Java Config機制之後,我們會越來越多的使用@Configuration來註冊Bean,並且Spring Boot更廣泛地使用了這一機制,其提供的大量Auto Configuration大大簡化了配置工作

原创 Spring、Spring Boot和TestNG測試指南 - 使用Spring Boot Testing工具 原 薦

Github地址 前面一個部分講解了如何使用Spring Testing工具來測試Spring項目,現在我們講解如何使用Spring Boot Testing工具來測試Spring Boot項目。 在Spring Boot項目裏既可以使用

原创 Spring、Spring Boot和TestNG測試指南 - 使用Spring Testing工具 原

Github地址 既然我們現在開發的是一個Spring項目,那麼肯定會用到Spring Framework的各種特性,這些特性實在是太好用了,它能夠大大提高我們的開發效率。那麼自然而然,你會想在測試代碼裏也能夠利用Spring Framew

原创 Spring、Spring Boot和TestNG測試指南 - 共享測試配置 原

碼雲地址 在使用Spring Boot Testing工具中提到: 在測試代碼之間儘量做到配置共用。 ... 能夠有效利用Spring TestContext Framework的緩存機制,ApplicationContext只會創建一次

原创 Spring、Spring Boot和TestNG測試指南 - @TestConfiguration 原

碼雲地址 @TestConfiguration是Spring Boot Test提供的一種工具,用它我們可以在一般的@Configuration之外補充測試專門用的Bean或者自定義的配置。 @TestConfiguration實際上是一種

原创 Spring、Spring Boot和TestNG測試指南 - @ActiveProfiles 原 薦

碼雲地址 @ActiveProfiles可以用來在測試的時候啓用某些Profile的Bean。本章節的測試代碼使用了下面的這個配置: @Configuration public class Config { @Bean @Prof

原创 Spring、Spring Boot和TestNG測試指南 - @OverrideAutoConfiguration 原 薦

碼雲地址 在Chapter 1: 基本用法 - 使用Spring Boot Testing工具裏提到: 除了單元測試(不需要初始化ApplicationContext的測試)外,儘量將測試配置和生產配置保持一致。比如如果生產配置裏啓用了A

原创 Spring、Spring Boot和TestNG測試指南 - @JsonTest 原

碼雲地址 @JsonTest是Spring Boot提供的方便測試JSON序列化反序列化的測試工具,在Spring Boot的文檔中有一些介紹。 需要注意的是@JsonTest需要Jackson的ObjectMapper,事實上如果你的Sp

原创 Spring、Spring Boot和TestNG測試指南 - @TestPropertySource 原

碼雲地址 @TestPropertySource可以用來覆蓋掉來自於系統環境變量、Java系統屬性、@PropertySource的屬性。 同時@TestPropertySource(properties=...)優先級高於@TestPro

原创 Spring Boot & Spring MVC 異常處理的N種方法 原 薦

github:https://github.com/chanjarster/spring-mvc-error-handling-example 參考文檔: Spring Boot 1.5.4.RELEASE Documentation S