All Projects → rafaeltoledo → okir

rafaeltoledo / okir

Licence: Apache-2.0 license
A helper class that implements both an Espresso IdlingResource and an OkHttp Interceptor

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to okir

Android Livedata Viewmodel
Android app that demonstrates how to use new Architecture components.
Stars: ✭ 114 (+322.22%)
Mutual labels:  espresso, okhttp
Okreplay
📼 Record and replay OkHttp network interaction in your tests.
Stars: ✭ 697 (+2481.48%)
Mutual labels:  espresso, okhttp
MyFrame
一个简易的Android快速开发框架 ,集成了好多大神的框架
Stars: ✭ 13 (-51.85%)
Mutual labels:  okhttp
QSHttp
Android安卓http/https一句代码联网络框架net framework
Stars: ✭ 14 (-48.15%)
Mutual labels:  okhttp
gateway
API proxy gateway base on netty and okHttp.
Stars: ✭ 21 (-22.22%)
Mutual labels:  okhttp
TDDWeatherApp
Android App trying to apply TDD and using MVVM, Kotlin Coroutines
Stars: ✭ 38 (+40.74%)
Mutual labels:  espresso
metrics-okhttp
An OkHttp HTTP client wrapper providing Metrics instrumentation of connection pools, request durations and rates, and other useful information.
Stars: ✭ 18 (-33.33%)
Mutual labels:  okhttp
ui-testing
No description or website provided.
Stars: ✭ 15 (-44.44%)
Mutual labels:  espresso
okhttp kit
dart版okhttp - https://github.com/square/okhttp
Stars: ✭ 16 (-40.74%)
Mutual labels:  okhttp
GuildWars2 APIViewer
Guild Wars 2 API Viewer: An Android application used for viewing various Guild Wars 2 API endpoint responses. Developed utilizing MVVM architecture, in conjunction with Databinding, Dagger 2, Retrofit 2, and RxJava 2.
Stars: ✭ 53 (+96.3%)
Mutual labels:  espresso
RxHttp
基于RxJava2+Retrofit+OkHttp4.x封装的网络请求类库,亮点多多,完美兼容MVVM(ViewModel,LiveData),天生支持网络请求和生命周期绑定,天生支持多BaseUrl,支持文件上传下载进度监听,支持断点下载,支持Glide和网络请求公用一个OkHttpClient⭐⭐⭐
Stars: ✭ 25 (-7.41%)
Mutual labels:  okhttp
decent-visualizer
A visualizer for .shot files
Stars: ✭ 46 (+70.37%)
Mutual labels:  espresso
allure-kotlin
Allure integrations for test frameworks targeting Kotlin and Java with 1.6 source compatibility.
Stars: ✭ 40 (+48.15%)
Mutual labels:  espresso
windigo-android
Windigo is easy to use type-safe rest/http client for android
Stars: ✭ 23 (-14.81%)
Mutual labels:  okhttp
Kriptofolio
Free open source minimalistic cryptocurrencies portfolio app for Android.
Stars: ✭ 79 (+192.59%)
Mutual labels:  okhttp
ehhttp
OkHttp calls as RxJava types
Stars: ✭ 19 (-29.63%)
Mutual labels:  okhttp
GitMessengerBot-Android
타입스크립트, V8 엔진의 자바스크립트, 파이썬 그리고 Git을 지원하는 최첨단 메신저 봇!
Stars: ✭ 51 (+88.89%)
Mutual labels:  okhttp
OkSimple
OkSimple :powerful and simple okhttp network library
Stars: ✭ 57 (+111.11%)
Mutual labels:  okhttp
iMoney
iMoney 金融项目
Stars: ✭ 55 (+103.7%)
Mutual labels:  okhttp
Android-Model-View-Presenter
No description or website provided.
Stars: ✭ 26 (-3.7%)
Mutual labels:  okhttp

OkHttp Idling Resource

A helper class that implements both an Espresso IdlingResource and an OkHttp 2 and 3 Interceptors.

Build Status Android Arsenal

Usage

Just create an instance of the desired implementation,

@RunWith(AndroidJunit.class)
public class MyEspressoTest {

    private OkHttp3IdlingResource okir = new OkHttp3IdlingResource();
}

register it on Espresso,

    @Before
    public void setUp() {
        Espresso.registerIdlingResources(okir);
    }

    @After
    public void tearDown() {
        Espresso.unregisterIdlingResources(okir);
    }

add it to your OkHttpClient and replace it on your production code.

    ...
    @Before
    public void setUp() {
        Espresso.registerIdlingResources(okir);
        OkHttpClient client = ApiCaller.getClient().newBuilder()
                .addInterceptor(okir)
                .build();
        ApiCaller.setClient(client);
    }

For a working example, check the sample folder.

It's recommended to annotate your setter method with @VisibleForTesting to avoid the accidental change on production code. Another way to do this is through the Java's reflection API.

Customization

For some cases (e.g., using the OkHttpClient instance for both Retrofit and Picasso), you only want to wait for some URLs. If you need this behavior, just pass the URLs you want to wait in the constructor.

// I just want to wait for requests to Github's API.
OkHttp3IdlingResource okir = new OkHttp3IdlingResource("https://api.github.com");

It's highly recommended to mock your requests when testing. A great solution is to use Square's MockWebServer

Download

The library is available on JCenter. Add the library as an Android Test dependency:

dependencies {
    ...
    androidTestCompile 'net.rafaeltoledo.okir:library:0.0.1@aar'
}

License

Copyright 2016 Rafael Toledo

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].