如何使数据文件可用于单元测试? [英] How do I make a data file available to unit tests?

查看:38
本文介绍了如何使数据文件可用于单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VS2008 TFS(带有MSTest).

I'm using VS2008 TFS (with MSTest).

我有一个可靠的单元测试,它依赖于项目子文件夹(即testproject1 \ TestData)中的数据文件.数据文件属性为构建操作=内容",始终复制". (它本身不是测试数据文件,而是生产代码读取并通常期望在其自己的文件夹中的文件)

I have a unit test that works reliably, relying on a data file in a subfolder of the project (ie testproject1\TestData). The data file properties are Build Action=Content, Copy Always. (It is not a test datafile as such, but a file that the production code reads and normally expects in its own folder)

构建并执行测试后,数据文件已正确复制到... \ TestResults \(testruniD)\ Out文件夹中,并且经过测试的代码找到了它.

When the test is built and executes, the data file is correctly copied to the ...\TestResults\(testruniD)\Out folder, and the tested code finds it.

现在,我将测试及其数据文件移动到解决方案中的另一个测试项目中(它应在的位置),该数据文件位于相对于新测试项目(testproject2 \ TestData)的同一文件夹中,并且数据文件属性仍如上检查.但是,在重建时,由于数据文件尚未复制到测试结果输出文件夹中,因此执行代码找不到该新位置,因此测试无法在新位置进行.

Now, I move the test and its data file to another test project in the solution (where it really should be), The data file is in the same folder relative to the new test project (testproject2\TestData), and the data file properties are checked as still being as above. However on rebuild the test fails in the new location because the data file has not been copied to the test results output folder so the executing code cannot find it.

我应该做些额外的事情来确保仍然复制数据文件吗?

Is there something extra I should have done to ensure the data file is still copied?

我以前有一个相关的问题,其中一些数据文件被复制到测试结果输出文件夹,而某些数据文件(出于显而易见的原因)没有被复制,这使我感到困惑.

I've had a related problem before, whereby some data files are copied to the test results output folder and some are not, for no apparent reason, and it bewilders me.

TIA

推荐答案

使用更多信息这里).

根据操作说明, .testrunco​​nfig文件也必须进行编辑.

这篇关于如何使数据文件可用于单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆