How to do integration testing in .NET with real files?

后端 未结 5 1039
孤独总比滥情好
孤独总比滥情好 2020-12-23 09:17

I have some classes that implements some logic related to file system and files. For example, I am performing following tasks as part of this logic:

  • checking i
5条回答
  •  甜味超标
    2020-12-23 09:45

    I don't know your program's architecture to give a good advice, but I will try

    1. I believe that you don't need to test real file structure. File access services are defined by system/framework, and they're don't need to be tested. You need to mock this services in related tests.
    2. Also you don't need to test MEF. It is already tested.
    3. Use SOLID principles to make unit tests. Especially take look at Single Responsibility Principle this will allow you to to create unit tests, which won't be related to each others. Just don't forget about mocking to avoid dependencies.
    4. To make integration tests, you can create a set of helper classes, which will emulate scenarios of file structures, which you want to test. This will allow you to stay not attached to machine on which you will run this tests. Such approach maybe more complicated than creating real file structure, but I like it.

提交回复
热议问题