我想知道测试服务到服务呼叫的最佳方法是什么?目前,每个服务都驻留在一个单独的子模块中。 e.g。
ViewsLog.record_between(3.day.ago, Time.now)
/project
/cat-service //Location of CatController
/dog-service //Location of DogController, CatClient
看起来像这样:
CatController
class CatController
{
int callCounter = 0;
public int getCallCounter() { return callCounter; }
@RequestMapping(method = GET, value = "/catservice/simple")
public Object callCat() {
callCounter++;
return "purrrrrr";
}
}
看起来像这样:
DogController
class DogController
{
@Autowired
CatClient catClient;
@RequestMapping(method = GET, value = "/dogservice/simple")
public Object callDog()
{
//In here make a call to the catservice over the network.
catClient.callCatService();
return "Woof woof";
}
}
看起来像这样:
CatClient
为了测试从dog-service到cat-service的调用,我将在dog-service中包含cat-service进行测试:
@FeignClient("cat")
public interface CatClient
{
@RequestMapping(method = GET, value = "/catservice/simple")
public Object callCatService();
}
然后在测试类中:
// dog-service/build.gradle
testCompile project(path: ':cat-service')
有更好的方法吗?这有什么严重的缺陷吗?