file.dart
file.dart copied to clipboard
What is the best way to check in a unit-test if all randomaccessfile objects are closed properly?
I am wondering how I can best write test code to ensure the code under test properly closes open files. For example:
Future<int> readAbit(File f) async {
final raf = await f.open();
return await raf.readByte(); /// should have wrapped this in a try-finally
}
The file f
is opened inside readAbit
. A unit-test would not have access to the raf
variable to check if it is closed.
Usually returning raf
doesnt make much sense. It would be much more helpful to be able to inspect f
and check for any dangling RandomAccessFile
objects.