Now, add a new test called testPlacesService() to our RetrofitClientTest class. Override fun getVenueRecommendations(query: Map): Call = In the Test, we will verify that API Execution return Success result.įirst, let's create our Client Class that provide an instance of Retrofit Object with a valid BASE_URL class RetrofitClient Usually, youll want to execute the request asynchronously with the enqueue. Second, we will create Endpoint and Service class for Retrofit, and we will test our First API Calling with Retrofit. The Call class is the starting point for every network request with Retrofit. We want to acheive some basic testing for this article.įirst, we will have an instance of Retrofit object which contain a valid BASE_URL and in Test, we will make sure that the BASE_URL Retrofit has, is same as our's BASE_URL More about Unit Tesing What will be our Acheivement? To serialise JSON we need a converter to convert it into Gson first. To make retrofit use a Callback converting the possible success/errors cases to the Result type we need to wrap the callback in a callAdapter.Retrofit automatically serialises the JSON response using a POJO (Plain Old Java Object) which must be defined in advanced for the JSON Structure. A unit may be an individual function, method, procedure, module, or object. Retrofit 2 by default leverages OkHttp as the networking layer and is built on top of it. Unit Tests isolate a section of code and verify its correctness. Unit Testing is done during the development (coding phase) of an application by the developers. The purpose is to validate that each unit of the software code performs as expected. Unit Testing is a type of software testing where individual units or components of a software are tested. The library provides a powerful framework for authenticating and interacting with APIs and sending network requests with OkHttp.Äetail about Retrofit & How it works What is Unit Testing? Retrofit Error Handling Raw CallResultAdapterFactory.kt import retrofit2.Call import retrofit2.CallAdapter import retrofit2.Response import retrofit2. Retrofit is a type-safe REST client for Android, Java and Kotlin developed by Square. If get to know something new by reading my articles, don't forget to endorse me on LinkedIn What is Retrofit?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |