Unit Testing File I/O

后端 未结 6 1785
故里飘歌
故里飘歌 2020-11-29 20:58

Reading through the existing unit testing related threads here on Stack Overflow, I couldn\'t find one with a clear answer about how to unit test file I/O operations. I have

6条回答
  •  旧时难觅i
    2020-11-29 21:29

    Currently, I consume an IFileSystem object via dependency injection. For production code, a wrapper class implements the interface, wrapping specific IO functions that I need. When testing, I can create a null or stub implementation and provide that to the class under test. The tested class is none the wiser.

提交回复
热议问题