Is it considered bad practice to use a flat file when doing unit tests? If an application reads in flat files and parses them, would this be a better approach than hard coding strings into the unit tests themselves?
Flat File in a Unit Test
unit testing
It's only bad practice for sure if the text files aren't checked into version control.There isn't anything hugely wrong with reading text files, provided the text files are in source control along side the class reading it. However, I personally would rather hard code all the values into a bunch of lists because they are being used for unit tests. There is nothing wrong with that. Where I work I work on software that analyzes data from real world sensors. I have written python scripts that will take the flat text files and convert those into C# static class files ready for being plugged into the unit tests.