SankethBK / diaryvault

A personal diary application written in Flutter
https://play.google.com/store/apps/details?id=me.sankethbk.dairyapp
MIT License
86 stars 59 forks source link

Add integration tests for basic CRUD operations #57

Closed SankethBK closed 10 months ago

SankethBK commented 11 months ago

We can add integration tests using integration_test package. Refer this docs for more details.

We can add integration tests around CRUD operations for notes. Initially we can use Continue as guest as option in signup page, create a new note with title and body, save it and check it is displayed in home page.

We can similarly check by updating an existing note to check if updation is working, and delete a note and check if it is removed from home page

PratyushChauhan commented 11 months ago

I'm done with my previous issue. Please assign this to me.

SankethBK commented 11 months ago

Sure

PratyushChauhan commented 11 months ago

@SankethBK could you point me to the directory where i can find all crud operations?

SankethBK commented 11 months ago

@PratyushChauhan In integration testing we simulate the actual actions like clicking the button, writing something in textbox, etc. Checkout this video for more info.

While testing we need to avoid network calls, so when the app opens you can simulate following steps for a test

  1. Wait for signup page to load
  2. Click on "Continue as guest" button as signup or login will trigger network calls
  3. Make sure you are in home page
  4. Click the FAB (create note button)
  5. Check if you're in note create page, add some title and body
  6. Save the note
  7. Verify if note is appearing in home page.

You can come up with multiple scenarios like this for updating, deleting notes as well

PratyushChauhan commented 11 months ago

Got it thanks

PratyushChauhan commented 11 months ago

After following the tutorial I made a simple unit test for guest login

import 'package:dairy_app/app/view/app.dart';
import 'package:dairy_app/core/pages/home_page.dart';
import 'package:dairy_app/features/auth/presentation/pages/auth_page.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

Future<void> main() async{
  IntegrationTestWidgetsFlutterBinding.ensureInitialized();

  testWidgets('Guest login test, click on sign up button to move reveal guest login button'
      'click the guest login button to enter HomePage', (WidgetTester tester) async {
    await tester.pumpWidget(App());
    await tester.pumpAndSettle();
    await tester.tap(find.text('Sign up'));
    await tester.pumpAndSettle();
    await tester.tap(find.text('Continue as guest'));
    await tester.pumpAndSettle();
    expect(find.byType(HomePage), findsOneWidget);
    expect(find.byType(AuthPage), findsNothing);
  });
}

Upon running flutter test path/to/guestlogintest.dart i got an unexpected error.

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following StateError was thrown building _InheritedProviderScope<ThemeCubit?>(value: <not yet
loaded>):
Bad state: GetIt: Object/factory with type AuthSessionBloc is not registered inside GetIt.
(Did you accidentally do GetIt sl=GetIt.instance(); instead of GetIt sl=GetIt.instance;
Did you forget to register it?)

The relevant error-causing widget was:
  _InheritedProviderScope<ThemeCubit?>
  _InheritedProviderScope:file:///C:/Users/ciphe/AppData/Local/Pub/Cache/hosted/pub.dev/provider-6.0.5/lib/src/inherited_provider.dart:161:12

Full stack trace can be found here.

PratyushChauhan commented 11 months ago

Is it a state management related exception?

SankethBK commented 11 months ago

@PratyushChauhan can you share the PR, i will try it out locally. It appears like get_it ins't initialized, because of which its not able to find dependencies.

PratyushChauhan commented 11 months ago

PR initiated