Reputation: 3507
My library's structure is:
mylib
lib
mylib.dart
src
example.dart
test
utilities.dart
I'd like to export some helper functions I've written in this library so they can be used in the test files of other libraries.
In mylib.dart, which contains exports for the other classes in the library (e.g. export 'src/example.dart';
, the following line causes an error:
export '../test/utilities.dart';
The error is:
Target of URI doesn't exist: '../test/utilities.dart'.
It seems I can only export files under the lib
folder. I imagine this is a security thing, so I don't go exporting files from just anywhere on my computer.
Is it possible to export a file that contains utility functions for tests, if that file lives under the test
folder? Or should I put those utility functions in a file under the lib
folder, even though they only pertain to testing, and should only be used in other libraries' tests?
Upvotes: 0
Views: 803
Reputation: 90015
If you have test code that you want to share in tests for other packages, you should put your code in the lib/
directory (or in its own package) and expect that non-testing code would just not bother import
ing it.
If you have test code that you want to share in tests in the same package, you can leave it in your test/
directory (or in a subdirectory), and test files in test/
can import
it via the relative path.
Upvotes: 2