Testing Firebase Database with an in-memory fake/db - android

Is there any in-memory implementation for Firebase database for testing Android client logic and integration? I have seen node.js fakes but could not find anything in java. I am not looking for a plain mock which is only good for basic unit-testing.

You must do refactoring your application, and implement an architectural approach. For example, such as MVP, MVVM, Clean, etc. The main thing is the layers. In this case, you can test these layers independently of each other using mock objects.
On the Internet you will find a lot of documentation on this topic,
eg Essential Guide For Designing Your Android App Architecture,
Why to choose MVVM over MVP — Android Architecture and many others.

Related

Which architecture is suitable for realtime chat application like whatsapp?

I want to develop a real-time chat application in Android like WhatsApp or telegram
for the all-purpose client should connect to the server via WebSockets and even
offline or online has to works fine. I decided to use Android architecture like MVP, MVVM, and MVI, but I'm confusing which one is suitable for my app
Can anyone help me to choose one of them?
And my second question: is it ok to use WebSockets for all APIs or it should better use WebSockets and REST APIs together?
Thanks for your help
There are quite a few patterns out there for app architectures. The most well known are the classic three-tier architectures such as:
MVC: Model-View-Controller.
MVP: Model-View-Presenter.
MVVM: Model-View-ViewModel.
All these patterns represent the main similar idea — to structure your project’s code in a way that it is separated by the different generic layers. Every layer has its own responsibility. That’s why your project becomes modular: separated code parts are more testable, and your app is flexible enough for continuous changes.
MVP is strongly recommended because a lot of developers are using it now. Even, Google also provides its best practice example on Github. You can see full document here.
I strongly recommend you use MVVM because Google has adopted this approach for Android Projects recently. You can find a lot of examples about it. Especially LiveData and ViewModel mechanisms have a lot of advantages in terms of separation of concerns and managing the relations between ui and data.

Need help learning to write tests for this Android app (Kotlin, MVVM, Room, Dagger2)

https://github.com/Spheniscine/dimsum-leadmanagement
I am currently a beginner to Android development.
This is an Android app I am currently working on, notes on its current working state is in the description. I am currently trying to learn how to write more robust code using MVVM (Model-View-View Model) for a testable architecture, and was supposed to learn TDD (test-driven development) patterns, but I seem to have hit a snag as to writing the actual tests.
There are a number of instrumented tests already here testing the simplest navigation stuff, but I am having trouble figuring out the best way to write tests for things like whether a salesperson shows up on the list or whether adding a salesperson works, without referencing or affecting the actual database on the phone. I'm also struggling to write unit tests for the backend (SalespersonMngViewModel and DimsumRepository)
From what I can glean, I need to use something called Dagger to inject a mock database or repository as needed... as evidenced by the "di" folder, I have managed to use it to make the repository injectable, however I am having trouble figuring out how to actually use it for testing. Additionally, I am having trouble figuring out how to extend that pattern to inject the ViewModel. From the tutorials and info I looked around for, it seems to require something called a ViewModelFactory, which again, I am having trouble understanding how to implement.
The problem is that the tutorials I found either talked about a whole bunch of other dependencies (e.g. Retrofit, RxJava, Glide) that I haven't had time to learn about yet, or were missing key features or use cases that I needed (e.g. there was an MVVM tutorial I followed that didn't have testing, and then there was a testing tutorial that used MVVM, but with neither a Room database nor dependency injection)

Android Architecture Questions

I've been reading about architecture to android projects. And I found some stuff, but I guess I misunderstood some concepts or not even understood at all.
One of my questions is about handling api objects, if I have a local database, Should I use the same object from api to store in local database?
I'm also looking for explanation about why use MVVM or MVP, actually they looks like different stuff, I have figured out that MVP is a pattern more concerned about handling UI responsibilities, MVVM I think is oriented to handle communication between UI and database. So I misunderstood the concepts or it make sense?
The last but not least important topic is about dependency injection, I have read about the concept and this question came to my mind, why should I use any framework as dagger to handle this, if I can handle this pattern by myself, once it's not thaaat complicated?
Should I use the same object from api to store in local database?
It can really depend on how good your API object is. You should rather base your local database object on what it really mean in a logical way and if your endpoint is well done it could be the same. The important part in your architecture is to isolate your logic parts from your I/O parts (UI, database, API) so if you want to redesign your UI, change the Webservice you use it will not be too painful.
So I misunderstood the concepts or it make sense?
I am not that familiar with MVVM so I can not really answer that question. But for me the important is not to follow "by the book" one pattern or another but rather to adapt your architecture from what you like from each. I currently try do to so with the Clean Architecture. You can take a look at all the concepts Uncle Bob speak about in this article about making code cleaner and more maintainable.
why should I use any framework as dagger to handle this, if I can handle this pattern by myself, once it's not thaaat complicated?
You don't have to use dagger if you're not familiar with it. But if your project start to grow and you start to be a team of 2, 3, 5... working on it, a framework as dagger can help you keeping a common standard about how you make your dependency injection and then making the code more coherent. Dagger also provide some tools as scopes that can save you some time if you're familiar with it.

Android architecture components with MVP

New Android Architecture Components released on google IO 17.
So should we use MVP with architecture components and MVVM?
In google sample on Github, they have used the MVVM model.
Google Sample
About the selection of architectural pattern and its implementation, it always depends on many factors such as team members, app's types, and so on.
In Google's blog post, they have already said that Architecture Components are mainly
Opinions not Prescriptions.
However, three main components (Room, ViewModel, ViewData) are developed with wide-range usage but not focus on any specific pattern.
For example,
If you are using SQLite to persist local data in your app, you can
you Room no matter what kind of pattern you are using, it is really a
great library with a lot of benefits such as reducing boiler plate
codes, validating SQLite syntax in compilation time, etc.
Besides, LifeCycle, LiveData, and ViewModel have their own strong
points. Especially, they address lifecycle-handling issues really well.
LiveData gives you one more tool of observer pattern which handles data stream reactively. (Like a great feature RxJava provides us).
...
At the end, for your question.
So should we use MVP with architecture components?
The answer is "it's nice part of Android framework, so why not".
Updated:
If you want to see how a MVP pattern project works with new Architecture Components, please checkout my repository on Github. In which I enhance previous MVP model by using Room for local persistence and LifeCycle to create lifecycle-aware Presenter.
I'm currently building a template project that uses MVP pattern along with Google Architecture components (Room, LiveData), and compare to mix version of Realm and LiveData:
https://github.com/duyp/mvp-template
I think some of Google Architecture Components are compatible with MVP Pattern, not only for MVVM :D
You can check out 2 following branches:
realm_livedata: MVP with Realm and LiveData
room_livedata: MVP with Room persistence library and LiveData
It's much more complex than Google sample project (I used Dagger 2, RxAndroid, Retrofit, Gson, and clean architecture) hope you find a better solution for your work. If any question or suggestion, you can leave comments or issues on my github project.
I also created a project using MVVM with new Google architecture components with Realm, Dagger 2, Live data: https://github.com/duyp/mvvm-template
Happy coding!

Architectures for RESTful Android Applications

I'm currently developing an Android application and I'd like to have an scalable architecture with a clean separation of concerns. The requirements of this application are, mainly:
User autentication (I'm dealing now with Google Sign-In for Android after many unsuccessful fights agains Android Identity Toolkit)
Synchronization with REST services (this application should be collaborative, I've already done a proof of concept to consume a "heartbeat" service, using AsyncService, that was the only way I've found to clean activies code, I got to that library researching about Robust Android Architectures)
ORM at client side to store user generated data and retrieved data in the future (my choice has been ORMLite for Android)
Material Design (as the best approach to the UI I have in mind)
First of all I'd like advices on how to separate classes inside the project, I mean, should I use folders (activity, model, DAL, service, sync...) or should I create my own libraries? (in .Net I'd create libraries with parent namespace)
My second and biggest concern is about user identity: how should looks like my architecture to achieve my goals? (sign up / Sign in with multiple providers, authenticated rest client and synchronization using SyncAdapter)
I hope you don bane this quiestion because maybe is too generic but I ask about all this stuff because I couldn't find information or advices about this stuff.
Thank you in advance.
This is a generic question and every dev has his own way to achieve this, but I would recommend to follow one of the trending patterns right now.
There is a project call the clean architecture. It has pretty much everything from dB to Api. In my opinion is a over-engineered.
I prefer another pattern called Flux.
Together with retrofit, eventbus or Otto makes building apps easy and keep the structure
You can read more about it here:
http://lgvalle.xyz/2015/08/04/flux-architecture/

Categories

Resources