copyResourceTo function

void copyResourceTo(
  1. String path,
  2. File file,
  3. {String prefix = _defaultPrefix}
)

Copies the test resource at the specified path into the provided File, creating it if necessary.

"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 the prefix by default).
  • File file - the file which will be a copy of the resource file data.
  • String prefix - the path prefix from the project root (defaults to test/resources).

Implementation

void copyResourceTo(String path, File file, {String prefix = _defaultPrefix}) {
  final sourceFile = resourceFile(path, prefix: prefix);

  if (!sourceFile.existsSync()) {
    throw Exception('Resource file ($path) does not exist.');
  }

  file.parent.createSync(recursive: true);
  sourceFile.copySync(file.path);
}