davidmartos96 / sqflite_sqlcipher

SQLite flutter plugin
BSD 2-Clause "Simplified" License
99 stars 44 forks source link

Unit Tests #69

Closed ZiiwareJordanc closed 1 year ago

ZiiwareJordanc commented 1 year ago

Is there any support for writing unit tests for this that does not involve mocking method channel? The only examples for tests I see in this project involve mocking the method channel which does not really help me test how to interacts with my code. id rather have it use the real methods.

davidmartos96 commented 1 year ago

@ZiiwareJordanc Hello! Yes, unit tests are supported, but you need to use Dart FFI capabilities for that. Take a look at this comment: https://github.com/davidmartos96/sqflite_sqlcipher/issues/68#issuecomment-1424163455

ZiiwareJordanc commented 1 year ago

Im confused, the example is for sqflite_common_ffi and not sqflite_sqlcipher am i missing something?

This may be a dumb question but how does this help me make it so when i call openDatabase from the sqflite_sqlcipher in a unit test that it does not fail due to not finding methods on the method channel.

all of the factory work seems to be handled internally for the databaseFactory getter unlike in the main sqflite package which contains a way to set it.

ZiiwareJordanc commented 1 year ago

I guess it might be or might not be relevant information that im trying to run these unit tests through android studio.

davidmartos96 commented 1 year ago

@ZiiwareJordanc sqflite_common it's a dependency of sqflite_sqlcipher. There is not much we could do in this library, as you need to tell Dart where you are loading the sqlcipher native .so library for it to work in desktop.

So on your unit tests, you basically need to overwrite how you are opening the database so that it uses FFI. Then everything would work the same behind the scenes.

ZiiwareJordanc commented 1 year ago

I think i finally got things sorted out. Thanks.