Testing with Mockito in Flutter

ActivityItemHelper before
ActivityItemHelper test before
ActivityItemHelper after
ActivityItemHelper test after
  • Line 3: Initialize sqflite_common_ffi.
  • Line 6: Create a test database for testing purpose.
  • Line 7: Create the table that I can test.
  • Line 18: Create mock of MockDatabaseProvider generated from @GenerateMocks([DatabaseProvider]) .
  • Line 19: Returns future test database when DatabaseProvider.database is called . See Line 7 of ActivityItemHelper from above.
  • Line 20: Create the class to test.
  • Line 28: Insert data.
  • Line 30–41: Expect inserted data.
  • Line 42: Close and delete database so we can run other tests.

Personal Notes

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store