スキップしてメイン コンテンツに移動

投稿

ラベル(Mock Test)が付いた投稿を表示しています

Automated Testing: Mock Test

Today's topic is Mock Test . In the previous posts, I introduced bunch of test cases but all of target class is class which hits actual service or production environment. However in the real world, in many cases we cannot simply use actual service class. Isolate from actual production service. ex. storing DB, calling external environment API. External API is too slow and we don't have to use acual data from the API but just would like to test clsasses which uses the API. Would like to controla data from API. Would like to test internal logic. You can use Mock Object, which we can control behaviour of class, for the above cases. There are a lot of Mock libraries (especially in Java). In this post, we use Mockito for explanation. You just downalod mockito-all-x.x.x.jar and include it to classpath, then you can use Mockito. Mockito Example Code I think you can easily understand how to use Mockito from the below code example. package com.dukesoftware.exchangerate.s