3 ms·
> Avoid loading CSVs or Parquet files as sample data. (It’s fine for evals but not unit tests.) Define sample data directly in unit test code to test key functi
by Hackbraten 3y ago
> Avoid loading CSVs or Parquet files as sample data. (It’s fine for evals but not unit tests.) Define sample data directly in unit test code to test key functionality
How does it matter whether I inline my test data inside the unit test code, or have my unit test code load that same data from a checked-in file instead?
- Zanfa 3y agoIt makes tests self-contained and easier to reason about. As a side-effect, random tests won’t accidentally break whenever you change some seemingly unrelated csv file. As a rule of thumb, I also only assert on input/output values that are explicitly defined as part of the test body. Saves a ton of time chasing down fixture definitions.
- jononor 3y agoDon't make the files "seemingly unrelated". Have a very clear relationship between test data and the tests. And keep the mapping simple, ideally 1-1 data file to test. Or 1 file to 1 group of tests. Of course it depends on the amount of data. If < 50 lines, inlining is practical.