Improve unit test infrastructure - allow control of write()