微服務場景下的自動化測試(3)

發表于:2016-10-04來源:icodeit.org/作者:icodeit.org點擊數: 標簽:微服務
1 ); boolean isExpiredOn = license.isExpiredOn( fixed .plusYears( 1 ).plusDays( 1 ).toDate()); assertTrue(isExpiredOn);}@Test public void license_should_not_expire_before_the_evaluation_period() { Loc
1); boolean isExpiredOn = license.isExpiredOn(fixed.plusYears(1).plusDays(1).toDate()); assertTrue(isExpiredOn); } @Test public void license_should_not_expire_before_the_evaluation_period() { LocalDate fixed = getDateFrom("2015-09-05"); License license = new License(fixed.toDate(), 1); boolean isExpiredOn = license.isExpiredOn(fixed.plusYears(1).minusDays(1).toDate()); assertFalse(isExpiredOn); }

上面這個例子就是一個非常典型的單元測試,它和其他組件基本上沒有依賴。即使要測試的對象對其他類有依賴,我們會Stub/Mock的手段來將這些依賴消除,比如使用mockito / PowerMock 。

集成測試

系統內模塊(一個模塊對其周邊的依賴項)間的集成,系統間的集成都可以歸類為集成測試。比如

  • 數據庫訪問模塊與數據庫的集成
  • 對外部 service 依賴的測試,比如對第三方支付,通知等服務的集成

集成測試強調模塊和外部的交互的驗證,在集成測試時,通常會涉及到外部的組件,比如數據庫,第三方服務。這時候需要盡可能真實的去與外部組件進行交互,比如使用和真實環境相同類型的數據庫,采用獨立模式(Standalone)的 WireMock 來啟動外部依賴的RESTful系統。

通常會用來做模擬外部依賴工具包括:

原文轉自:http://icodeit.org/2016/10/testing-in-microservice-context/

...

熱門標簽

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97