Here is my c# unit test design issue:
I have one test that I want to run on some code that modifies a file. My test will run the code that modifies the file, then check the result. Pretty straight forward so far…
The issue is, I have about 10 files (soon to be a lot more) that I want to run the same unit test against. I dont want to write a new unit test for each file, when the test itself is really the same.
I could write a single test that queries the files in the folder and then runs the test logic on each file, but using this method would only report one pass/fail result for the entire set of files.
Id like to create some sort of dynamic system where every file that I place in a particular folder gets ran though this same unit test. So if 25 files are in the folder, the test gets ran 25 times, and the unit test reults report that 25 tests were ran, and includes seperate pass/fails for each.
Any ideas how or if this can be done in a c# unit test? Or with a nunit test?
Thanks! And I hope this is not a duplicate question. I looked around, but I could not find anything.
Another option is to use T4 templates to dynamically generate tests for you based on the number of files in your directory. Add this “.tt” file to your unit test project.
Now whenever you do a build which should happen just before you press the “Run all tests in solution” button in visual studio, it should generate unit tests for all the files in the directory with the file name in the unit test. Then your test run should have a nice list of all the files it tested and their statuses.