我是新的單元測試在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'.
我怎樣才能在執行文件夾中添加此文件?
在此先感謝。 (和對不起我的英語......)
看起來像這樣柱的重複所有文件:[在單元測試樣品數據] [1] [1]:HTTP: // @ tackoverflow.com/questions/5383987/how-can-i-include-sample-data-files-in-vs-unit-tests – Clueless
@無色:確實。我沒有找到這個帖子。謝謝。 – Hyralex
也相關 - https://stackoverflow.com/questions/5581628/c-sharp-test-resources – sashoalm