copyResourceInto function
Copies the test resource at the specified path
into the provided
Directory
as a File
with the same filename as the original.
"Test resources" are files stored (by default) under the test/resources/
directory of the project root. This prefix may be changed, using the
prefix
argument.
Arguments
String path
- the relative path (from theprefix
by default).Directory dir
- the directory where the file is to be copied.String prefix
- the path prefix from the project root (defaults totest/resources
).
Implementation
void copyResourceInto(
String path,
Directory dir, {
String prefix = _defaultPrefix,
}) {
final sourceFile = resourceFile(path, prefix: prefix);
if (!sourceFile.existsSync()) {
throw Exception('Resource file ($path) does not exist.');
}
if (!dir.existsSync()) {
dir.createSync(recursive: true);
}
sourceFile.copySync('${dir.path}/${sourceFile.uri.pathSegments.last}');
}