如何让MSTest查找我的测试数据文件? [英] How to get MSTest to find my test data files?

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

问题描述

我有一些测试需要与excel文件中的外部数据配合使用.这些文件包含在测试项目中,并且在Visual Studio中,我已经编辑了测试设置文件(Local.testsettings)以部署数据文件.这使它在VS中可以正常工作.

I have a few tests that need to be fed with external data from excel files. The files are included in the test project, and in Visual Studio, I have edited the test settings file (Local.testsettings) to deploy the data files. This makes it work fine i VS.

但是,我们还在与TeamCity进行持续集成,而在TeamCity中这是行不通的.我的数据文件不可用于测试.似乎测试是从名为"C:\ TeamCity \ buildAgent \ temp \ buildTmp \ ciuser_AS40VS6 2009-12-11 09_40_17 \ Out"的临时文件夹中运行的,并且数据文件未复制到此处.

We are, however, also running continous integration with TeamCity, and in TeamCity this doesn't work. My data files are unavailable to the test. Seems that the tests are run from a temporary folder named "C:\TeamCity\buildAgent\temp\buildTmp\ciuser_AS40VS6 2009-12-11 09_40_17\Out", and the data files are not copied there.

我尝试将数据文件的生成操作更改为资源",并将复制到输出dir的设置设置为始终",但这无济于事.

I have tried changing the build action for the data files to "Resource" and setting copy to output dir to "Always", but that didn't help.

有人知道如何进行这项工作吗?

Does anyone know how to make this work?

我正在运行Visual Studio 2010 beta 2和TeamCity 4.5.5,这就是为什么我首先运行MSTest而不是NUnit的原因...

I am running Visual Studio 2010 beta 2 and TeamCity 4.5.5, which is why I'm running MSTest in the first place, and not NUnit...

推荐答案

我通过添加数据文件(在我的情况下通常为XML)作为嵌入式资源来解决这个问题,并从测试程序集中提取它们.

I get round this by adding my data files (in my case usually XML) as embedded resources and I extract them from the test assembly.

[TestInitialize]
public void InitializeTests()
{
    var asm = Assembly.GetExecutingAssembly();
    this.doc = new XmlDocument();
    this.doc.Load(asm.GetManifestResourceStream("TestAssembly.File.xml"));
}

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

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