我想在颤动测试中使用JSON文件模拟HTTP响应。在gitlab CI上,测试正在通过。本地也是如此。但是在codemagic.io上有一个错误:
FileSystemException: Cannot open file, path = 'test_resources/mock_response.json' (OS Error: No such file or directory, errno = 2)
发布于 2019-09-30 15:59:00
这与flutter test sets current directory differently depending on how test was executed相关。apaatsio in the first comment提供的解决方案对我很有效。
例如,你可以有这样的东西:
import 'dart:io';
import 'package:path/path.dart';
String loadResource(String name) => File("$_testDirectory/test_resources/$name").readAsStringSync();
// From https://github.com/flutter/flutter/issues/20907#issuecomment-466185328
final _testDirectory = join(
Directory.current.path,
Directory.current.path.endsWith('test') ? '' : 'test',
);然后使用它:
final mockResponse = loadResource('mock_response.json');https://stackoverflow.com/questions/55185557
复制相似问题