开发者

Running a data driven unit test off more than one input file

开发者 https://www.devze.com 2023-03-28 16:19 出处:网络
Background: In our project, we have a bunch of xml files that define tests that are loaded into a report generator. Since we want to make sure our tests stay accurate, we have data driven unit tests s

Background: In our project, we have a bunch of xml files that define tests that are loaded into a report generator. Since we want to make sure our tests stay accurate, we have data driven unit tests set up to test that the xml input produces the same output. This is currently held in a large excel spreadsheet, and works great with Visual Studio's data driven unit tests. But, this leads to problems because often more than one developer will be working on tests, and they will need to get the spreadsheet to add the unit tests. If another developer has the spreadsheet, then they are stalled waiting on it to get checked back in since VS can't merge the excel file. In addition, we are wanting to switch to git, and this approach won't work well there either due to the lack of locking on checkouts and inability to merge binary files.

So, we are trying to switch to having a separate file for each individual test's set of unit tests in a folder. Then, when the unit tests are run, we load up all the files in the folder and run the test data in each of the files. This way, when a developer makes a new test, they just have to add a new 开发者_如何学Cfile for the unit tests, instead of having to add an entry to a central file.

The data format is going to be the same across all the files, so really, even concatenating them together should work. But, I'm trying to do this and retain the data driven behavior where each row in the test data is equivalent to one test in the output; they all pass or fail/produce output messages separately.

Is it possible to run a data driven unit test off of multiple files? If so, can we still retain the 'one row == one test' style output in the results?


I wound up having a ClassInitialize method for the unit test class and made the class include the folder of files I needed as a deployment item. Then, the ClassInitialize method took all of the data files in the folder and concatenated them together. The other tests in the class then referenced this file in their DataSource attribute. This allowed me to use the multiple file layout and still retain the output style we wanted.

Main lesson out of this: The data source file for a data driven unit test does not have to exist at compile time, apparently.

0

精彩评论

暂无评论...
验证码 换一张
取 消