How to wait for asynchronous configuration in unit test, in Dart?

My unit tests require an installation that must run asynchronously. That is, I need to wait for the installation to complete before the tests run, but the setup is for Futures.

+7
source share
1 answer

With Dart M3, the setUp function can return a Future if necessary. If setUp returns the future, the unittest framework will wait for future work to complete before running individual test methods.

Here is an example:

 group(('database') { var db = createDb(); setUp(() { return openDatabase() .then((db) => populateForTests(db)); }); test('read', () { Future future = db.read('foo'); future.then((value) { expect(value, 'bar'); }); expect(future, completes); }); }); 

Learn more about setUp .

+10
source

All Articles