Reputation: 14713
Super noob with unit testing...
I have a method that processes and then deletes an input file. How can I unit test the if the file actually gets deleted? I understand it's a bad practice to do actual file IO during a unit test.
Thanks!
Upvotes: 1
Views: 207
Reputation: 136613
It's not an absolute rule - if you're class lives on the periphery i.e. interfaces with some external subsystem (in this case the filesystem), then the right way to test it is with the real subsystem.
The GOOS book deems these tests as "integration tests" because these tests test whether your class integrates with the external subsystem.
The consumers of this class can abstract away the file system via an interface exposed by this class.
My question/acid test for this decision is - what is the primary responsibility of this class ?
Upvotes: 1
Reputation: 9089
Have the method do a System.IO.File.Copy() of the source file and then use the copy to do your testing. Hopefully, your code is setup to specify which file to process.
Upvotes: 0