file.dart icon indicating copy to clipboard operation
file.dart copied to clipboard

What is the best way to check in a unit-test if all randomaccessfile objects are closed properly?

Open jeduden opened this issue 2 years ago • 0 comments

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 rafdoesnt make much sense. It would be much more helpful to be able to inspect f and check for any dangling RandomAccessFile objects.

jeduden avatar Oct 14 '21 07:10 jeduden