2015-06-21 117 views
0

我使用Retrofit为我的REST API实现了Java客户端。客户端是一个简单的Java应用程序,而不是一个Android应用程序。我如何为我的Java客户端编写单元测试?以下是我的服务班之一。如何测试使用Retrofit实现的REST客户端

public interface CountryService { 

    /** 
    * Returns country list. 
    * 
    * @param sortby 
    *   Optional; Sorting order of list. Pass null to ignore. 
    * 
    * @return Countries object with list of countries. 
    * 
    * @throws SRSRetrofitException 
    */ 

    @GET(SRSClientConstants.SLASH + SRSClientConstants.RESOURCE_COUNTRY) 
    public Countries getCountries(@Query("sortby") String sortby) 
      throws SRSRetrofitException; 
} 
+0

这看起来像[此问题]的副本(http://stackoverflow.com/q/17544751/515948)。 –

+0

我最终实现了这个问题的答案。 – TechCrunch

回答

-1

由于在线托管REST应用程序,您只需使用GET/POST和其他HTTP方法来查询服务。不需要特殊的结构。尝试发送包含所有有效参数的HTTP请求。它应该工作。有关REST的更多信息click here

+0

问题是如何对使用Retrofit编写的客户端进行单元测试以获取REST API。我不明白你的答案。 – TechCrunch

+0

这可能有一些帮助... http://stackoverflow.com/questions/17544751/square-retrofit-server-mock-for-testing –