In the spirit of unit testing im trying to keep away from using a test file in my test project.
In the battle between idealism and pragmatism, sometimes a truce is needed.
The main push for not using test files is threefold:
- Your job isn't to test reading files from disk, it's to test the stuff at hand.
- Having files tends towards multiple tests using the same file, which in turn tends towards the tests not being isolated.
- Reading from disk is pretty much always going to be slower.
Which conflict against three of the core traits of unit tests: fast, isolated, focused.
But you're right. Having giant blobs of xml in your tests isn't terribly maintainable or pretty. Simply placing a small file into your test project isn't a gross violations of these motivations. In C#, loading a file is dead simple and nearly foolproof. You'll need to work to keep the file isolated to keep it from being an inter-test dependency, and you may need to move it back to code if it slows your tests too much.