我正在关注这篇文章http://blog.danlew.net/2015/11/02/sharing-code-between-unit-tests-and-instrumentation-tests-on-android/,以分享代码,但是如何分享一个资产?,像一个夹具文件?,我想模拟一个api响应,所以我有一个JSON文件来做,但我试试这个:https://gist.github.com/nebiros/91a68aaf6995fa635507
在单元测试中,这适用于:
ClassLoader.getSystemResourceAsStream("some_response.json");
Run Code Online (Sandbox Code Playgroud)
但是在Android Intrumentation Tests中,它没有,我在哪里可以放置那些夹具文件?
我正在使用JSONAPI,所以我需要包装一些类,但不是所有类,如:
{"users": {"aKey": "aValue"}} // wrapped.
{"aKey": "aValue"} // not wrapped.
Run Code Online (Sandbox Code Playgroud)
有一种方法可以动态地或从类本身禁用tis功能吗?
我试试这个:
包装/解包我正在这样做:
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
objectMapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE);
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
JacksonConverterFactory jacksonConverterFactory = JacksonConverterFactory.create(objectMapper);
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.interceptors().add(new LoggingInterceptor());
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.client(okHttpClient)
.addConverterFactory(jacksonConverterFactory)
.build();
Run Code Online (Sandbox Code Playgroud)
我需要一些POJO禁用该功能,这可能吗?
谢谢.
有没有办法将JSONAPI规范用于Retrofit?,不知道这将如何工作或如何启动,任何帮助?
我找到了这个要点:https://gist.github.com/Gregadeaux/cbcc3781fda9d7fa6498,它使用RxJava和其他一些库.
还需要转换器吗?
谢谢.