Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在单元测试输出目录中添加内容文件_C#_Visual Studio_Unit Testing - Fatal编程技术网

C# 在单元测试输出目录中添加内容文件

C# 在单元测试输出目录中添加内容文件,c#,visual-studio,unit-testing,C#,Visual Studio,Unit Testing,我是VisualStudio中单元测试的新手,我想加载一个物理xml文件。 该文件作为内容存在于单元测试项目中,并复制到输出目录中 因此,在编译项目时,xml文件位于输出目录中。 但是当我执行测试时,会创建一个包含所有依赖DLL的新目录,但不会复制xml文件 执行测试需要Xml的内容。我执行此代码以检索执行文件夹中Xml文件的路径: private static string GetXmlFullName() { // GetApplicationPath use the current

我是VisualStudio中单元测试的新手,我想加载一个物理xml文件。 该文件作为内容存在于单元测试项目中,并复制到输出目录中

因此,在编译项目时,xml文件位于输出目录中。 但是当我执行测试时,会创建一个包含所有依赖DLL的新目录,但不会复制xml文件

执行测试需要Xml的内容。我执行此代码以检索执行文件夹中Xml文件的路径:

private static string GetXmlFullName()
{
    // GetApplicationPath use the current DLL to find the physical path
    // of the current application
    string executeDirectory = AssemblyHelper.GetApplicationPath();
    return Path.Combine(executeDirectory, "content.xml");
}
例外情况是:

System.IO.DirectoryNotFoundException: 'd:\***\solutiondirectory\testresults\*** 2012-06-13 17_59_53\out\content.xml'.
如何将此文件添加到execute文件夹中

提前谢谢。(对不起,我的英语…)

你需要在考试课上放一个a

例如,包括数据文件夹中的所有文件

[TestClass()]
[DeploymentItem("Data")]
public class MyTestClass
{
    ...
}

看起来像是这篇文章的副本:[单元测试中的样本数据][1][1]:@clauless:的确如此。我没有找到这个帖子。谢谢。也是相关的-DeploymentItem属性只有在项目上的生成操作设置为Content,并且复制到输出目录设置为Copy if Newer或Copy always时才起作用。我还必须在解决方案项->Local.testsettings中启用部署,并添加我想要部署的目录。呸!