我有一个使用Office PIA的Excel包装类。我也有一个以前写在NUnit上运行的有限测试套件。我们正在工作中迁移到TFS2010,所以我也将NUnit测试迁移到MSTest。在Team Build 2010下运行针对Excel的单元测试的异常
测试套件在我的开发机器上运行良好,并且如果在运行构建代理的机器上使用MSTest命令行实用程序手动执行。但是,当通过Team Build执行时,所有与磁盘I/O(打开,保存等)有关的测试都会失败。我的构建代理正在域帐户上运行,并且该域帐户也是同一台计算机上的本地管理员。少数不做任何磁盘I/O的测试运行良好,所以我知道Excel正在被解雇和可用。只是看起来像一个权限问题或团队建设过程的限制。
所以这里是一个示例函数。这就是我认为这是Excel I/O问题的原因。 File.Exists检查传递正常。我在测试运行中没有收到FileNotFoundException,而是直接从Interop层收到COMException。
public void OpenXLS(string workbookFilePath)
{
// Make sure given file path exists
if (!File.Exists(workbookFilePath))
{
throw new FileNotFoundException(String.Format(CultureInfo.CurrentCulture,
"File '{0}' cannot be found.", workbookFilePath));
}
// Open the Workbook
_xlsWorkbook = _xlsWorkbooks.Open(workbookFilePath, 0, false, Missing.Value,
"", Missing.Value, true, Missing.Value, Missing.Value, true, false,
Missing.Value, Missing.Value, Missing.Value, Missing.Value);
}
例外:
System.Runtime.InteropServices.COMException: Microsoft Excel cannot access the file
'C:\BuildPath\TestResults\TestRun\Out\TestBook.xls'. There are several possible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open
请发布您收到的全部例外。 – 2011-04-15 20:05:27