Problem: I want to know which data go to Firebase Firestore and Firebase Authentication.
In my project, I'm using pure Firebase without RxJava or something else.
Here is my project on GitHub: https://github.com/Artemius-dev/Projemanag_Trello_Clone
I have found only one solution so far.
Firstly you need to make sure that you have good architecture in your app. Then make sure that you can add DI to your project if you haven't done it already
Secondly, make separate DI (Dagger or Hilt) for AndroidTest
(preferably not necessary add some common Interface for example: to add Notes or Users to your app so you can implement the same Interface in your AndroidTests and inject it to your main app with new methods which will be only executed in your tests so you won't add anything in your production code)
Thirdly use Firebase Emulator Suite to work with not production data and database
P.S (As I have seen so far the Firebase Emulator Suite is the best solution to test Firebase)
Related
I'm going to use cloud functions for firebase to recursively delete documents and collections in Firestore that is triggered by HTTP request (I'm using HTTP Callable function specifically). I have found some useful information from the following links:
https://firebase.google.com/docs/functions/callable
https://firebase.google.com/docs/firestore/solutions/delete-collections
But I'm not sure about one thing: It looks like from the tutorial, the functions are written locally and then deployed to cloud server. So where do I keep all the functions and their dependencies? If I keep the local written function within my android project, then each time when I update the function locally I will have to publish a new version of the app, which is too much work. Is it ok to start the local written function in another folder other than the android project? Also, if I want to start writing the function directly at cloud functions at GCP (so that I can update the function in cloud server), where can I get the dependencies files such as package.json, package-lock.json and .eslintrc.json etc.? I didn't find useful tutorial to that. Can someone help me? Thanks!
To answer your questions, first you can keep your functions and dependencies anywhere as long as you have access and logged your account to the CLI with the right project configured in it. Each time you update your function locally then yes, you have to redeploy it.
If you want, you can consider setting up CI/CD with your Firebase Functions so you can automate deployments whenever you hit commit on master and staging branch of your repo.
Second, you can start the local written function anywhere, as long as it contains the right dependencies for your app. As Doug mentioned, it doesn't matter how your files are organized.
And third, the dependencies files such as package.json, package-lock.json, and .eslintrc.json is something that you need to provide on your own. I suggest that you read through their docs and see what works best for you.
If I keep the local written function within my android project, then each time when I update the function locally I will have to publish a new version of the app, which is too much work.
That's not true. It doesn't really matter where you project files are organized. You can still deploy the function whenever you want. It's completely separate from your app code.
Is it ok to start the local written function in another folder other than the android project?
If that's your preference, then do it. As I mentioned, it doesn't matter how your files are organized.
Also, if I want to start writing the function directly at cloud functions at GCP (so that I can update the function in cloud server), where can I get the dependencies files such as package.json, package-lock.json and .eslintrc.json etc.?
If you're having problems working with functions in the console, you should ask a separate question about that and indicate where you are stuck in that process.
I am following clean architecture, and I understand the use of the repository for actions like getUsers or queryUsers. However does not make sense to me the use of a repository to login a user. How should I communicate with the Data Layer then, should I skip the repository layer and access the network layer?
I definitely think that you should not skip layers.
The whole point of introducing a certain architecture is to follow it without exception, so all your app modules behave in an expected and predictable way.
So, if you look at it from a different angle, what does logging in mean? You get a username and a password and you must check if they match a username and a password that are stored in your datasource. To do this, you run a query against your current users. And queries are run where - in the repository! You said it yourself - the repository is where all querying should happen. What is implementation behind it is of no importance.
So, my suggestion is to add a method like this one:
public interface UserRepository {
User findByUsernameAndPassword(#NonNull String username, #NonNull String
password);
}
If you manage to find a user - good, he's authenticated, if not - sorry, try again.
from this guid i think using repository is a better choice. my answer based on the definition of the repository quoting :
Repository modules are responsible for handling data operations.
I believe in clean architecture you should not skip layers. I see a few options here:
userRepository.get\set-User() - for me, it looks a bit weird because Repository is an abstraction over collection while we need only one.
create an abstraction over user storage. For example, userStorage.get\set-User() or userStorage.login(User), logout(), get()
I am using the Clean Architecture in my currently project. Now I want to integrate a feature that request Facebook SDK to execute login.
Im my opinion, Facebook SDK acts as a Data-Provider (which provide authentication service, similar to other Restful login API) and should be setup and using under data module instead of app module. For example if I want to execute Facebook Login, I will invoke appropriate use-case, then such use-case will call data module to do actual work.
But, the challenge is Facebook method (see Facebook's LoginManager, Here ), require Activity/Fragment instance to run.
So, should I move Facebook SDK back to appmodule or pass the Activity instance down to storage module?
I don't really like any options of them. (felling not happy although it helps to resolve requirement). Does anyone have any better approach?
Thanks
In order to strictly follow clean architecture u have to keep all frameworks out of ur inner circles (app module). This includes Facebook SDK as well as Android itself.
The usual way to access frameworks from business rules in Clean Architecture is trough abstractions.
In ur use case I would suggest the following:
create IActivity interface in app module to abstract activity/fragment
create ILoginManager in app module which takes IActivity
create AndroidActivity which implements IActivity in framework layer
create FacebookLoginManager which implements ILoginManager in framework layer
from ur android activity when calling the use case interactor pass the activity as IActivity and the FacebookLoginManager as ILoginManager
the FacebookLoginManager would then have to cast IActivity back to the android activity and pass it to the LoginManager from Facebook SDK
This approach would add some more classes and interfaces to ur project but also clearly separate concerns and dependencies.
I'm building a library that is using Firebase database.
when i'm taking the exported .aar and importing it via another app - i get the following error:
FirebaseAuthException: This operation is not allowed
the original app didnt allow the firebase database option - so we get this message. problem is I don't need to use the app's Firebase database within the sdk - what I want is the lib's (aar) firebase database to modify.
maybe if there was a way to define two google-services.json files, one for the aar and one for the app - without them overriding themselves?
how can an autonomous firebase database within a library?
You basically need to have an instance of FirebaseApp created from your library credentials. See this blog, it might help.
Instead of creating and managing 2 different google.json files (I'm not sure whether it's possible or not but even if it is..), i think it's better to wrap your library's firebase database instance and expose a neat api for the consumer apps to interact with your library's database.
So i've recently started using Xamarin.UITest in my mobile application. Its great for testing the UI, navigation etc. However im slightly confused as to how the best way is to test all the other parts of the app i.e the database, web connection, model and so on.
The project is cross-platform using a shared project.
Should these other tests be in along with the UITests or do they need their own separate project?
Furthermore in Xamarin Studio on OSX is there a way to test particularly the .Net only code without having to build and launch the whole iOS app?
Thanks
This question is really broad.
UI tests should only test the UI itself
Does navigation work correctly?
Is everything displayed like it should?
Are UI components visible, enabled, read-only etc.
Do components display correct data?
Your business logic should be tested in a unit test project
Do your classes process incoming data correctly?
Do they trigger the correct methods with the correct parameters in all cases?
Do they prepare the correct calls to webservices, databases or third party libraries? (You don't test the correct behaviour of other pieces of software here)
Do they throw exceptions as expected?
Unit tests are helping you the most to fix and avoid bugs. They are in general much more important for high quality code than all the other tests.
Integration tests are used to test the rest
Do databases, webservices, file system, operating system API work like expected?
Does it all work correctly together?
Does it all work fast enough?
There are many good books and links about good testing. It's way too much then to do it here.
Just a few examples:
http://blog.stevensanderson.com/2009/08/24/writing-great-unit-tests-best-and-worst-practises/
https://developer.xamarin.com/guides/ios/deployment,_testing,_and_metrics/touch.unit/
http://blog.falafel.com/hold-right-learning-xamarin-unit-tests/
How to do integration testing in .NET with real files?
With these links, StackOverflow and Google you will find out that your unit tests should stay in a separate project. Mock your business logic as good as possible in your UI tests. So that they don't test all your code. Otherwise you will result in UI tests which often fail in order to changes inside your business logic. You would have to change the UI tests everytime you change the unit tests. That becomes annoying and frustrating quickly.
The main scenario that you're asking about is an integration test.
Since your tests drive the app from the UI layer, it's of course invoking all the code in the app and touching all the backend systems. But you're hoping to validate that the app and its supporting set of backend services all work correctly.
First of all, you'll need a way to expose data about your backend service to the test. You already did this, since the app probably uses a REST API and a database. For tests, you'd probably only want to do this for a staging or pre-production endpoint, somewhere that you won't be at risk for exposing real data by accident. You could configure a simple RESTful API that gives information about your backend services, and then invoke that from the test. You could also use backdoor methods which, in turn, call the API and prevent you from needing to make extra API calls from the test. Let's take a basic example, creating a new user.
Your test code might look something like this pseudocode:
var uniqueUser = Guid.NewGuid().ToString();
app.EnterText(firstName, "Test 1");
app.EnterText(lastName, uniqueUser);
app.Tap(createUserButton);
app.WaitForNoElement(e => e.Id("progress"));
app.WaitForElement(e => e.Text("User successfully created"));
// At this point, call your API using RestSharp or whatever makes sense for you
string endpoint = "https://my.server.net/user/getByLastName/" + uniqueUser;
var client = new RestClient(endpoint);
var result = ExecuteRequestHereAndItShouldReturnUserJSON();
Assert.IsTrue(result != null && result.FirstName == "Test 1");
That type of thing.
On teardown, you'd want to invoke a method to delete the test user by its id to avoid clogging up your database with test users created by the thousands of devices in Test Cloud. You could do this via backdoor or REST, whichever is safer depending on your current setup.
As for testing the code itself, just create a separate unit test project and use NUnit. There are a lot of great resources on testing listed in the other answer that can help you understand how to write good unit tests, when/how to use mocking, etc.