Here's what I do - it works for me, but it may not be according to your specifications.
In the passage I make sure that I delete any files that I could create as part of the package. So yes, make sure the file is a scratch file for testing
In the testing method, I delete the file if it exists (it should not, since the trimming has already taken care of this), and then output the file to XML, and then confirm that the file exists. Then I reload the file either in the object graph or in the DOM xml and request the state through as many statements as you need.
If you can get away with writing to files, and your design allows you to write to a common text script or XML writer, you can bypass file saving and replace calls with a string writer and just request a string. Much cleaner, but it does not check the operability of the actual file.
source share