Skip to content

8. Tests & Developers Tips

Faisal Ramdan edited this page May 28, 2021 · 1 revision

Tests

  • Be sure you have backed up the database before you are going to test since the test will delete the whole database(or at least some collection) to make a propro test. In is recommended to test on a separate (inactive) Firebase project.

Unit Test

Since getxfire is a bit complicated and depends on many other packages, we found out that the standard unit testing is not an ideal option. So, we wrote our own simple unit test code.

You can add the code below in Home screen. You need to fix the import path.

Chat unit test

  • To do unit test of chat
import 'file:///Users/thruthesky/apps/dating/packages/getxfire/test/chat.tests.v2.dart';GetxFire ff = GetxFire();
ff.init({});
ChatTest(inject: ff).runTests();

Test code creates chat room with hatch option and leaves out of the room, the test may produce unhandled exception if you do not run test code in order. The best wayy to test the code is to remove the chat collection from firestore and run full test code.

After test, you need to remove the code from main.dart

Integration Test

Please read Testing Flutter apps for details about Flutter app testing.

We don't do unit testing on getxfire since its backend is Firebase and there is no doubt about Firebase's performance and quality assurance.

And we don't do widget testing. Instead, we do integration test.

  • See sample app's intergration-test branch for the codes.

  • We have tested it on Android app only since iOS app displays push notification consent box and it annoys the test.

  • Youtube video on integration test

IMAGE ALT TEXT HERE

Developers Tips

Test with user accounts

  • You may delete user account from Firebase Auth menu to register with same phone number.

Extension method on getxfire

  • To write an extension method, see the example below.
import 'package:getxfire/getxfire.dart';
extension on GetxFire {
  getUid() {
    return user.uid;
  }
}
print('uid: ' + ff.getUid());

Extending your app with Fireflutter

You can do so much things with Fireflutter. We will introduce some scenario how getxfire could extend your app's functionality.

Social photo gallery

Imagine that you are going to build a social app. User can upload his photos and manage it on his profile page while those photos are public. User can see other users' photos and take actions like voting(like and dislike), commeting, and even reporting for abusement.

  • You can create a forum named gallary and put add photo button in user's profile screen.
  • When user uploads a photo with firelfutter upload method, create a post under gallery forum with getxfire method.
  • You can, then, get(listen) user's photo with getxfire post fetch method and display it to screen.
  • When user wants edit or delete photo, do so with getxfire.

This may cause lots of time and effort to accomplish without getxfire.

Keeping deleted post when user delete post

Sometimes you may want to keep the deleted post. Imagine that you are going to build a photo gallery and keeping history of uploaded photos are mandatory.

  • When user deletes a post which has the photo,
  • Don't delete the document. Instead delete the title and content, add a property {deleted: FieldValue.serverTimestamp()}
  • And when the app lists the posts, hide deleted posts.
Clone this wiki locally