mardi 25 février 2020

Flutter test - verifying assets exist

I have a flutter app which contains a large list of quotes, each with an associated audio file.

I've written a simple test that verifies all the specified audio files are where they're supposed to be, in case of typos etc:

test('specified audio file should exist for all quotes', () {
    ALL_QUOTES.forEach((quote) {
      final expectedPath = 'assets/${quote.filename}.wav';
      final exists = new File(expectedPath).existsSync();
      expect(exists, isTrue, reason: '$expectedPath does not exist');
    });
  });

This passes fine in IntelliJ, however running from the command line using flutter test it fails on the first thing it looks for.

Is there a way of doing this which will work regardless of how it's run? Why does it pass one way but not the other?

Aucun commentaire:

Enregistrer un commentaire