[英]Add content file in unit testing output directory
我是 Visual Studio 中單元測試的新手,我想加載一個物理 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'.
如何在執行文件夾中添加此文件?
提前致謝。 (對不起我的英語......)
您需要在測試類上放置DeploymentItemAttribute 。
例如,要包含Data文件夾中的所有文件
[TestClass()]
[DeploymentItem("Data")]
public class MyTestClass
{
...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.