ResoCoder / flutter-tdd-clean-architecture-course

https://resocoder.com/flutter-clean-architecture-tdd/
2.01k stars 625 forks source link

fixture reader can't open file #13

Closed pratamawijaya closed 4 years ago

pratamawijaya commented 4 years ago

i'm trying running test with flutter test but it show error

test/features/number_trivia/data/models/number_trivia_model_test.dart:
 fromJson should return a valid model when the JSON number is an integer [E]

FileSystemException: Cannot open file, path = 'test/fixtures/trivia.json'
(OS Error: No such file or directory, errno = 2)
 dart:io  File.readAsStringSync 
fixtures/fixture_reader.dart 3:60                                       fixture
features/number_trivia/data/models/number_trivia_model_test.dart 26:25  main.<fn>.<fn>
sophiabrandt commented 4 years ago

If someone has the same problem: it looks like only VSCode can find the file path of the test file. If you're using a different editor, fix the file fixture_reader.dart like so:

import 'dart:io';

String fixture(String name) {
   var dir = Directory.current.path;
   if (dir.endsWith('/test')) {
     dir = dir.replaceAll('/test', '');
   }
   return File('$dir/test/fixtures/$name').readAsStringSync();
}

More information on this GitHub issue.

Merdin commented 1 month ago

This is what works for me:

String fixture(String fileName) =>
    File('./test/fixtures/$fileName').readAsStringSync();