简体   繁体   English

如何为目录中的每个文件运行Visual Studio单元测试?

[英]How do I run a Visual Studio unit test for each file in a directory?

I have a unit test that is currently set up to take inputs from a csv file defined using the DataSource attribute on the test. 我有一个单元测试,当前已设置为从使用测试上的DataSource属性定义的csv文件中获取输入。 I'd like to change this so that instead of condensing several files into a csv, the unit test would run for each file in a directory. 我想更改此设置,以便将目录中的每个文件都运行单元测试,而不是将多个文件压缩为csv。 Is there a way to create the datasource dynamically so that it contains the list of filenames in the directory? 有没有一种方法可以动态创建数据源,使其包含目录中的文件名列表?

There was essentially no way to do what I was originally asking. 基本上没有办法完成我最初要求的工作。 So instead, I created the test like normal, specifying a CSV/TXT file to be used as input for the test method. 因此,我改为像平常一样创建了测试,指定了一个CSV / TXT文件作为测试方法的输入。 However, I added a pre-build event to the test project that ran a PowerShell script which created the input file with the paths for all the files in the target directory. 但是,我向测试项目添加了一个预构建事件,该事件运行一个PowerShell脚本,该脚本使用目标目录中所有文件的路径创建了输入文件。 This worked flawlessly. 这完美无瑕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM