Best practices for file system dependencies in unit/integration tests

前端 未结 5 660
星月不相逢
星月不相逢 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:13

    There are two options for testing code that needs to read from files:

    1. Keep the files related to the unit tests in source control (e.g. in a test data folder), so anyone who gets the latest and runs the tests always has the relevant files in a known folder relative to the test binaries. This is probably the "best practice".

    2. If the files in question are huge, you might not want to keep them in source control. In this case, a network share that is accessible from all developer and build machines is probably a reasonable compromise.

    Obviously most well-written classes will not have hard dependencies on the file system in the first place.

提交回复
热议问题