我正在使用NUnit來測試一個功能,我需要將XML文件加載到對象。該XML文件位於控制檯應用程序的位置。NUnit中的Assembly.GetEntryAssembly()
我有以下方法,其中的配置將被讀取:在我NUnit測試
public string GetConfiguration(TempFlexProcessor processor)
{
var exePath = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
var configPath = Path.Combine(Path.GetFullPath(exePath), "configuration");
var configFile = string.Format(@"{0}.xml", processor.GetType().Name);
}
現在我有測試方法,我測試GetConfiguration:
[Test]
public void TempFlexProcessorExecuteTest()
{
#region Given
#endregion
#region When
var tempFlexProcessor = new TempFlexProcessor();
var actual = tempFlexProcessor.GetConfiguration(tempFlexProcessor);
#endregion
Assert.AreEqual("path of the file", actual);
}
但System.Reflection.Assembly.GetEntryAssembly ()爲空,請幫助。
的GetConfiguration方法是在控制檯應用程序類TempFlexProcessor和基本上,當我我試圖從NUnit調用GetConfiguration它尋找Nunit可執行程序集。即使我得到了TemplFlexProcessor的程序集,我也得到了一些臨時文件夾路徑。 – 2014-10-08 11:14:36
@MilindChavan:我以爲你說過它返回'null'?這與查找NUnit可執行程序集......與temp文件夾路徑不同,這可能是因爲您運行NUnit的方式。您可以將其配置爲複製要測試或不測試的程序集。也許你應該使用* current *目錄?我相信當前目錄通常保留爲包含原始測試程序集的目錄。 – 2014-10-08 11:20:34