How to use mockito to create mock api response in android [closed] - android

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I am trying to create a mock response of an api call in an Android app.
Is Mockito the best way to go for that? I wanted to create a mock json of the actual api call
so that it I can test my app behaviour for different responses.

If you're really interested in mocking actual HTTP responses (response body, status codes, etc.), you should take a look at MockWebServer.
But in most cases, it makes more sense to use Mockito or Mockk (if you're using Kotlin) to mock responses from your local data sources like Repositories or Use Cases. So consider this approach if you have at least minimal wrapping logic around low-level networking stuff like OkHttp / Retrofit.

Related

Where should backend API be called - in use case or in repository? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
We are doing architecture for our new android application that requires offline mode also and have a dilemma about one detail.
General recommended architecture is shown in this picture:
Now, this makes pressure on repository doing 2 things: communication with API and SQLite which can easily get very complicated + harder to test.
At the same time, we have Use Case in between ViewModel and Repository to orchestrate jobs done across multiple things: services, multiple repositories, etc...
The question is:
Should backend API be called from Repository or maybe better to do it in Use Case? And why?
IMO neither. Generally I prefer this kind of architecture layering:
RemoteSource - Communicates with your networking or bluetooth API. It essentially wraps the retrofit interfaces, and does mapping & thread switching to IO
LocalSource - Communicates with your DB api (Room, SqlDelight). Also mapping & thread switching
Repository - Handles the logistics, whether something should be fetched, cached, etc...
UseCase - Combines multiple type of entity operations between repositories
So TL;DR: you can create a RemoteSource abstraction over your Retrofit interfaces

Which better to get Json between Retrofit 2 and HttpUrlConnection [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I know two of it can be used to send http request and get the response from the server, then we can parse into Json object if we want. So:
Which is the best way to send request and get response from the server, Retrofit 2 or HttpUrlConnection?
Which is advantage and disadvantage between them?
Retrofit 2 and Volley are both great networking libraries for modern Android apps, but each has its own strengths that are worth weighing for critical projects. Use Retrofit if your use-case is a standard REST API with JSON responses and not too many custom requirements in terms of caching, request prioritization, retries, etc. Use Volley if you have unusual / fine-grained requirements, or if you anticipate needing a lot of flexibility from your networking layer in the future at the cost of more code. Use neither if you're downloading large files or streaming -- for that, use DownloadManager instead.
Note: HttpClient is deprecated Now
Need More, Find it here

retrofit v/s async task for one request [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I am already aware of the advantanges of retrofit and have used it in many scenerios. For a particular application , I need to call only 1 login API which will do authentication.
I am not sure if the advantages of retrofit are worth it for only one API. or is it a overhead and I should Http for sake of simplicity
If it is just a single request, then I'd say go with the simplest/lightest approach. But these things tend to evolve with time, therefore you are likely to find yourself in a position of adding another one, then another one...
Remember - networking mechanism is not an architectural decision. In fact, your application should not care what networking mechanism is being used - it should depend on a general interface that you define. You could start with implementing this interface using the simplest approach, and add a more complex implementation in case your networking requirements evolve. You could also implement several approaches and benchmark them...
So, whatever approach you choose, I recommend not to "pollute" your business logic with networking logic, but hide it behind interface. This way even if you make the wrong decision now, it will be a matter of few hours to fix it later.
For a single API call http is fine. As you know using library with your application is going to occupy user phone space when they install your application on their device. so for a single call, you are good to go with async task.

Should I use Google Volley instead of AsyncTask [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I did some research on Google Volley and found that it is somewhat easy and clean to use.
But I am still not sure as to what the advantages of using it are and whether I should still use the AsyncTask.
I know AsyncTask works as a background task and that it is separate but what about Volley?
Which one should I opt for?
This is mainly an opinion based question that is largely dependent on the needs of your particular application. Volley provides a lot of things for you out of the box, like network caching (assuming you're given correct cache headers from your server), and an easy to use API with all of your callbacks and different threading layers handled for you. So, it really depends on what you're looking. Personally, I think any production worthy application should use some sort of networking library that a team has spent plenty of time patching and prepping for you (rather than trying to reinvent the wheel), and since a Google team has gone through the trouble for doing this for you...why not?
One cannot compare Volley with an AsyncTask.
So your question makes no sense.

Why using a framework to make Http requests in Android instead of using its own classes to make this? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
There are many frameworks to make http requests in Android, like Retrofit and Volley. But also, Android has its own classes to make this type of request, like HttpURLConnection and HttpClient
So what is the advantage of using some framework like these mentioned?
My doubt is if there is some big advantage in make requests using some framework, instead of using Android native classes.
The advantage is things like retries, restarts, threading & synchronization, and state management will be handled for you. This comes at the expense of configurability, but it's not a huge expense.

Categories

Resources