SampleRetrofitSpiceRequest

SampleRetrofitSpiceRequest

我想用这个robospice-retofit example来做一些单元测试。问题是我在调用loadDataFromNetwork()方法时遇到了一些nullPointerException。这是测试代码

public class SampleRetrofitSpiceRequestTest extends InstrumentationTestCase {

private SampleRetrofitSpiceRequest sampleRetrofitSpiceRequest;

@Override
protected void setUp() throws Exception {
    super.setUp();
    sampleRetrofitSpiceRequest = new SampleRetrofitSpiceRequest(
            "octo-online", "robospice");
}

public void test_loadDataFromNetwork() throws Exception {
    List contributors = sampleRetrofitSpiceRequest.loadDataFromNetwork();
    assertTrue(contributors.size() > 0);
}
}

最佳答案

RetrofitSpiceRequest需要改造服务类实例(在您的例子中,是github类)才能工作。在调用sampleRetrofitSpiceRequest.setService(...)之前,使用适当的参数调用loadDataFromNetwork

08-04 02:03