Unit Testing
Guidelines for unit testing with PowerSync
For unit-testing your projects using PowerSync
(e.g. testing whether your queries run as expected) you will need the powersync-sqlite-core
binary in your project’s root directory.
- Download the PowerSync SQLite binary
- Go to the Releases for
powersync-sqlite-core
. - Download the binary compatible with your OS.
- Go to the Releases for
- Rename the binary
- Rename the binary by removing the architecture suffix.
- Example:
powersync_x64.dll
topowersync.dll
- Example:
libpowersync_aarch64.dylib
tolibpowersync.dylib
- Example:
libpowersync_x64.so
tolibpowersync.so
- Place the binary in your project
- Move the renamed binary to the root directory of your project.
This snippet below is only included as a guide to unit testing in Flutter with PowerSync. For more information refer to the official Flutter unit testing documentation.
If you have trouble with loading the extension, confirm the following
Ensure that your SQLite3 binary install on your system has extension loading enabled. You can confirm this by doing the following
- Run
sqlite3
in your command-line interface. - In the sqlite3 prompt run
PRAGMA compile_options;
- Check the output for the option
ENABLE_LOAD_EXTENSION
. - If you see
ENABLE_LOAD_EXTENSION
, it means extension loading is enabled.
If the above steps don’t work, you can also confirm if extension loading is enabled by trying to load the extension in your command-line interface.
- Run
sqlite3
in your command-line interface. - Run
.load /path/to/file/libpowersync.dylib
(macOS) or.load /path/to/file/libpowersync.so
(Linux) or.load /path/to/file/powersync.dll
(Windows). - If this runs without error, then extension loading is enabled. If it fails with an error message about extension loading being disabled, then it’s not enabled in your SQLite installation.
If it is not enabled, you will have to download a compiled SQLite binary with extension loading enabled (e.g. using Homebrew) or compile SQLite with extension loading enabled and include it in your project’s folder alongside the extension.
Was this page helpful?