-
-
Notifications
You must be signed in to change notification settings - Fork 521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Testing utilities #83
Comments
Thanks for the note. Testing is still a pain since there is no convenient way to run unit tests on iOS/Android (required here to have SQLite). I'm open to suggestion on how to do it:
Most of my tests involves running a flutter app on iOS or Android. Plugin and native code testing is still not perfect but usable. |
OK, thanks for the info. I'll see if I can come up with something. Just started to playing with your plugin today. Will post here when I have more ideas. |
I ended up writing a custom solution. Not very nice but it works for testing SQL commands in a flutter unit test (which unfortunately has become painfully slower since dart2). Basically it requires running an app (a SQFlite server) on either ios and android and running test that uses sqflite, forwarding plugins calls to web socket call to the server (json rpc 2 is easy to map with plugin invoke command). It kinds of work. Some info here: https://github.com/tekartik/sqflite_more/blob/dart2/sqflite_server/README.md It is a work in progress (no doc, some caveat) |
You can run sqlflite test just like you debug widget tests:
This will launch the device and run this particular test file. Still a pain as I still have to run these tests separately from the other unit tests. |
A working example from @kdaker would be amazing as this is a real pain point. Any chance you could put something up? |
@gmcdowell sure, here is a sample from my test file below.
Some caveats:
The code below is abstracted a bit, basically the SQLite class wraps the db object and is responsible for setting it up.
|
- Hard to mock sqflite currently because of the issue tekartik/sqflite#83.
* Change app name in ios and android - Capitalize * Unify the import statement in main.dart * Enhanced [Category] model - Add showDelete param to show close icon when long pressed. - Fixed typo on image name. - Initial map value should trigger integer by adding .index. - Define `toString` for debug ease. * Implment showCategory method - Add `getConsumeCategories` and `getIncomeCategories` in DbHelper to get different data at once. - Implement poping up the bottomSheet when clicking on the category. - Organize import statements. - Implement [CategoryItem] seperately to handle changes of state more clearly. * Installed auto_size_text package - To show full text in category item. * Fixed close icon for category_item * Installed fluttertoast to use toast easily * Renamed popup dialog in general.dart * Implement category delete - Seperated [CategoryItem] and [CategoryList] from [LedgerItemAdd] to control state. - Use `Key` to re-render item in `SingleScrollView` when state changes. * Use `SafeArea` for [CategoryList] * Implement [CategoryAdd] screen dialog - Decided to put this in screen widget rather than shared since it looks more like a screen. * Moved [CategoryAdd] to screen from shared * Beautifully add categories in CategoryAdd screen - All synced with local db. * Changed relative import path to absolute path using package:bookoo2 * Add korean to xcode localization - Related issue flutter/flutter#14128. * Fix null exception when category icon add is null * Select category and render selected in renderBox * Added test files - Hard to mock sqflite currently because of the issue - tekartik/sqflite#83.
@kdaker How do you debug breakpoints when you run this command? |
@GanZhiXiong flutter run -t test/my_sqflite_test.dart in Android studio, you can create a flutter configuration and specify the target (Dart entrypoint) to point to |
Is there any work planned for this ticket that allows the testing to be done independently of the platform. I want to be able to run unit test to test out my data access functionality without running it on the emulator. Is that going to be possible? |
Hi @debuggdapps I have a temporary solution which is based on It supports unit testing on Windows, Mac and Linux in regular flutter test (no emulator/simulator). |
@alextekartik, Thanks for this info. Does this allow to connect to a real sqlite database. Is it possible that i can create a test database and use that as a resource to run my unit test scenarios? |
Unfortunately I'm not sure. I would guess yes since I don't know about any binary incompatibility on the version installed so far. There has not been any format change since 3.0.0 according to this https://www.sqlite.org/formatchng.html. |
sqflite_common_ffi v1.0.0 has been published allowing using ffi on the desktop. It is based on moor_ffi (!) that provides a nice wrapper around sqlite libraries |
Hey, thanks for this great plugin! Just curious if there were any plans on providing testing utilities like some sort of in-memory stub implementation. Or if you have some other suggestions in regards to testing. I'd really like to avoid mocking platform channels.
The text was updated successfully, but these errors were encountered: