靜態方法如何返回不同的實現類？

com.example.Service service;

service = RealServiceClient.getService().getServiceId("1");


PS：我是Java新手。

最佳答案

Personally, I prefer to use a dynamic language for doing the mocks. I find that you can get a lot of the ability you need without a fancy framework. I use groovy a lot for writing my unit tests. See this page for more information on using Groovy closures instead of Mocks: http://groovy.codehaus.org/Developer+Testing+using+Closures+instead+of+Mocks