【问题标题】:How to test a REST client implemented using Retrofit如何测试使用 Retrofit 实现的 REST 客户端
【发布时间】:2015-09-06 19:05:54
【问题描述】:

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

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;
}

【问题讨论】:

  • 这看起来像是 this question 的副本。
  • 我最终实现了该问题的答案。

标签: java unit-testing junit retrofit


【解决方案1】:

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多