如何本机库复制到单元测试临时目录在Visual Studio 2010 [英] How to copy native libraries to the unit test staging directory in Visual Studio 2010

查看:185
本文介绍了如何本机库复制到单元测试临时目录在Visual Studio 2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目有一些本地库(DLL),我通常复制的通过目标的MSBuild 的到输出目录。还有当我运行的应用程序没有问题,但我写在Visual Studio和我每次运行单元测试,组件和可执行文件时一些单元测试是从输出目录到临时文件夹中复制: C:\path\to\MyProject\TestResults\myWorkStationName 2012-03-20 13_53_56\Out

My project has dependencies on some native libraries (DLLs) that I normally copy via the MSBuild targets into the output directory. There is no problem when I run the application, but I am writing some unit tests in Visual Studio and every time I run the unit tests, the assemblies and executables are copied from the output directory into the staging folder: C:\path\to\MyProject\TestResults\myWorkStationName 2012-03-20 13_53_56\Out

不幸的是,本机DLL不会复制到临时目录,并在每次测试运行生成临时目录。是否有一个MSBuild目标,允许我的东西复制到临时目录?

Unfortunately the native DLLs are not copied into the staging directory and the staging directory is generated on every test run. Is there an MSbuild target that allows me to copy stuff into the staging directory?

P.S。我不知道,如果临时目录是正确的说法,所以请原谅我的无知,如果它不是。)

P.S. I'm not sure if "staging directory" is the correct term, so please excuse my ignorance if it's not :).

推荐答案

从VS菜单:测试> 编辑测试设置> (设置文件)> 部署>检查启用部署并添加目录或文件

Solution wide deployment

From the VS menu: Test> Edit Test Settings > (settings file)> Deployment > check Enable deployment and add a directory or files.

注意在此功能只有一条:对现有的测试启用的部署不会工作到Visual Studio中重新启动。

Note for one caveat in this feature: enabled deployment for existing tests won't work until Visual Studio is restarted.

使用的 [DeploymentItem] 属性:

Use the [DeploymentItem] attribute:

[TestMethod()]
[DeploymentItem("testFile1.txt")]
public void ConstructorTest()
{
    // Create the file to deploy
    Car.CarInfo();
    string file = "testFile1.txt";
    // Check if the created file exists in the deployment directory
    Assert.IsTrue(File.Exists(file), "deployment failed: " + file +
        " did not get deployed");
}

这篇关于如何本机库复制到单元测试临时目录在Visual Studio 2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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