Unit testing code with a file system dependency

前端 未结 11 752
粉色の甜心
粉色の甜心 2020-11-29 16:50

I am writing a component that, given a ZIP file, needs to:

  1. Unzip the file.
  2. Find a specific dll among the unzipped files.
  3. Load that dll thro
11条回答
  •  旧巷少年郎
    2020-11-29 17:21

    As others have said, the first is fine as an integration test. The second tests only what the function is supposed to actually do, which is all a unit test should do.

    As shown, the second example looks a little pointless, but it does give you the opportunity to test how the function responds to errors in any of the steps. You don't have any error checking in the example, but in the real system you may have, and the dependency injection would let you test all the responses to any errors. Then the cost will have been worth it.

提交回复
热议问题