Office PIA를 사용하는 Excel 래퍼 클래스가 있습니다. 이전에 NUnit에서 실행되도록 작성된 제한된 테스트 스위트도 있습니다. 직장에서 TFS2010으로 이전 중이므로 NUnit 테스트 오버런도 MSTest로 마이그레이션하고 있습니다.Team Build 2010에서 Excel에 대한 단위 테스트를 실행하는 경우의 예외
테스트 스위트는 내 dev 컴퓨터에서 제대로 실행되며 빌드 에이전트를 실행하는 컴퓨터에서 MSTest 명령 줄 유틸리티를 사용하여 수동으로 실행됩니다. 그러나 팀 빌드를 통해 실행될 때 디스크 I/O (열기, 저장 등)와 관련된 모든 테스트가 실패합니다. 내 빌드 에이전트가 도메인 계정에서 실행 중이며 해당 도메인 계정도 같은 컴퓨터의 로컬 관리자입니다. 디스크 I/O를 제대로 수행하지 못하는 몇 가지 테스트를 통해 Excel이 실행되고 있고 사용 가능하다는 것을 알고 있습니다. 권한 문제 또는 Team Build 프로세스의 한계처럼 보인다.
여기 예제 기능이 있습니다. 이것은 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
받은 모든 예외 사항을 게시하십시오. –