I am working on a system that processes documents that are dumped into a target directory. I pick up the files by detecting the FileSystemWatcher OnChanged event.
As part of a unit test, how should I go about automating this? How should I organize the input files and the output files that get compared to verify that the transformations are correct? Is this something that is better handled by a batch file issuing diff commands?
Well, first consider what exactly it is that you want to test.
Is it that after you've detected that a file has change, it is processed correctly?
Or is it that the FileSystemWatcher class works?
Or is it that the operating system sends you the right notifications in the right order (where right basically means as you expect it)?
If only the processing has to be done, I would consider mocking up the watcher class, or use an IoC container to provide you with something that fires events for the unit test.
If it's wether the operating system provides the right events in the right order, then I would mock up the code that processes the file, just to save state that says "yes, I was told that this file had changed", and the unit test would then manipulate files in a temp-directory.
But be warned, the more outside complexity your unit test relies on, the more breakable it will be.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With