如何让 MSTest 找到我的测试数据文件?

发布于 2024-08-14 12:42:30 字数 462 浏览 3 评论 0原文

我有一些测试需要使用 Excel 文件中的外部数据。这些文件包含在测试项目中,并且在 Visual Studio 中,我编辑了测试设置文件 (Local.testsettings) 来部署数据文件。这使得它在 VS 中工作得很好。

然而,我们也在与 TeamCity 运行持续集成,但在 TeamCity 中这不起作用。我的数据文件无法用于测试。似乎测试是从名为“C:\TeamCity\buildAgent\temp\buildTmp\ciuser_AS40VS6 2009-12-11 09_40_17\Out”的临时文件夹运行的,并且数据文件不会复制到那里。

我尝试将数据文件的构建操作更改为“资源”,并将输出目录的副本设置为“始终”,但这没有帮助。

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

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

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.

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.

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?

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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冷清清 2024-08-21 12:42:30

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

[TestInitialize]
public void InitializeTests()
{
    var asm = Assembly.GetExecutingAssembly();
    this.doc = new XmlDocument();
    this.doc.Load(asm.GetManifestResourceStream("TestAssembly.File.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"));
}
行至春深 2024-08-21 12:42:30

这篇文章回答了这个问题:MSTest 将文件复制到测试运行文件夹

This post answers this question: MSTest copy file to test run folder

初心未许 2024-08-21 12:42:30

接受的答案在技术上是正确的。但是,根据我的经验,我发现将嵌入文件作为资源需要记住设置属性“嵌入资源”。当您拥有大量数据文件时,这将成为一个挑战。此外,随着数据文件数量的增加,单元测试程序集的大小不断增长。就我而言,我有超过 500MB 的测试数据文件,将它们全部打包到程序集中并不是一个好主意。

替代方案是什么?

让数据文件保持原样。不要使用DeploymentItemAttribute,不要使用嵌入资源。请参考我建议的解决方案如何我是否可以提供一个可用于单元测试的数据文件?

The accepted answer is technically correct. However, from my experience, I find that the embedding files as resources requires an additional step of remembering to set the property "Embedded Resource". This becomes a challenge when you have a large number of data files. Also, with increasing number of data files, the size of the unit test assembly keeps growing . In my case, I had over 500MB of test data files and packing all them into the assembly was not a good idea.

What is the alternative?

Let the data files remain as they are. Do not use DeploymentItemAttribute, do not use embedded resources. Please refer my proposed solution How do I make a data file available to unit tests?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文