Team Build 2010下针对Excel运行单元测试的异常

时间:2011-04-12 22:25:50

标签: excel tfs2010 team-build

我有一个使用Office PIA的Excel包装器类。我还有一个有限的测试套件,以前写在NUnit上运行。我们正在迁移到TFS2010工作,所以我也将NUnit测试迁移到MSTest。

测试套件在我的开发机器上运行良好,如果在运行构建代理程序的机器上使用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 

2 个答案:

答案 0 :(得分:4)

我有类似的问题,这个解决方案对我有用: http://blogs.msdn.com/b/sqlserverfaq/archive/2010/04/30/unable-to-open-excel-files-using-a-cscript-in-sql-server-jobs.aspx

“systemprofile”文件夹中似乎需要“桌面”文件夹。

  • 在位置C:\ Windows \ SysWOW64 \ config \ systemprofile

  • 下为Windows 2008 Server(x64)创建“Desktop”文件夹
  • 对于32位Windows 2008 Server,在位置C:\ Windows \ System32 \ config \ systemprofile

  • 下创建“Desktop”文件夹

答案 1 :(得分:0)

Harlam357,你结识了我的一天!

然而,似乎即使在64位计算机上,您也需要在 C:\ Windows \ System32 \ config \ systemprofile 中创建“桌面”文件夹。我已在两个目录中创建它以确保。并且不要忘记完全控制服务帐户,可能需要它。

相关问题