In my Flutter app, I use Isar DB.
According to the documentation, it is possible to use my Isar database in my unit tests.
Here is what I've tried so far, just to see if I can initialize Isar correctly in my tests:
void main()
{
late Isar isar;
setUp(() async {
await Isar.initializeIsarCore(download: true);
isar = await Isar.open(
[TagSchema],
inspector: true,
directory: 'test/isar',
);
});
test('Test query 1', () {
// ...
});
}
But when I run my test, even by using the -j 1
argument, I get the following error:
package:isar/src/native/isar_core.dart 144:5 _downloadIsarCore
Warning: At least one test in this suite creates an HttpClient. When
running a test suite that uses TestWidgetsFlutterBinding, all HTTP
requests will return status code 400, and no network request will
actually be made. Any test expecting a real network connection and
status code will fail.
To test code that needs an HttpClient, provide your own HttpClient
implementation to the code under test, so that your test can
consistently provide a testable response to the code under test.
IsarError: Could not download IsarCore library:
So how can I initialize Isar in a unit test, so I can test my queries?
Thanks.