Best practices for file system dependencies in unit/integration tests

前端 未结 5 577
星月不相逢
星月不相逢 2020-12-29 05:29

I just started writing tests for a lot of code. There\'s a bunch of classes with dependencies to the file system, that is they read CSV files, read/write configuration files

5条回答
  •  醉梦人生
    2020-12-29 06:11

    Usually, file system tests aren't very critical: The file system is well understood, easy to set up and to keep stable. Also, accesses are usually pretty fast, so there is no reason per se to shun it or to mock the tests.

    I suggest that you find out why the directory doesn't exist and make sure that it does. For example, check the existence of a file or directory in setUp() and copy the files if the check fails. This only happens once, so the performance impact is minimal.

提交回复
热议问题