davidmartos96 / sqflite_sqlcipher

SQLite flutter plugin
BSD 2-Clause "Simplified" License
96 stars 41 forks source link

Unit test error when try openDatabase with path getDatabasesPath #84

Closed quanhtsparkminds closed 7 months ago

quanhtsparkminds commented 7 months ago

00:18 +0 -1: Testing the /local-authenticate [E]
Test failed. See exception logs above. The test description was: Testing the /local-authenticate

══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════ The following MissingPluginException was thrown running a test (but after the test had completed): MissingPluginException(No implementation found for method getDatabasesPath on channel com.davidmartos96.sqflite_sqlcipher)

When the exception was thrown, this was the stack:

0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:308:7)

(elided one frame from package:stack_trace)
davidmartos96 commented 7 months ago

That's expected because this library runs on top of Flutter platform channels. You would need to use sqflite_common_ffi which opens a database connection via FFI if you need it in unit tests. You can check the official sqflite documentation for that.

https://github.com/tekartik/sqflite/blob/master/sqflite/doc/testing.md#using-sqflite_common_ffi

I would advise to use regular sqlite (no SQLCipher) for your tests, as it will be easier and you won't need to install SQLCipher binaries on your development machine (Windows, macOS, Linux). The SQLite and SQLCipher APIs are compatible so your business logic in your tests shouldn't be affected.