12

MS unit testing framework을 사용하여 C# 라이브러리를 테스트하고 있습니다. DeploymentItem attribute을 사용하여 배포 할 파일을 열어야합니다. 하지만 Test 배포 디렉토리에 파일을 배포하는 것은 아닙니다.DeploymentItem에서 파일을 배포하지 않습니다.

내 단위 테스트 프로젝트에서이 폴더에 TestFile 폴더를 만들었습니다. 여러 개의 파일이 있는데, a.txt, b.txt라고 말하면됩니다.

이제 Unit Test 클래스에서 DeploymentItem 특성을 추가했습니다. 그러나 파일이 복사되지 않습니다.

여기 내 코드입니다.

[TestClass] 
[DeploymentItem("TestFile")] 
public class CustomLibraryTest 
{ 
    public TestContext TestContext { get; set; } 

    [TestMethod] 
    [DeploymentItem(@"TestFiles\a.txt")] // THis should deploy a.txt to test deployment directory 
    { 
     var path = TestContext.TestDeploymentDir + "a.txt"; 
     // Now when I debug this unit-test, and open path in explorer, 
     // a.txt is not present in "TestResults\Deploy_fhafeez 2013-05-28 13_02_37\Out" folder 
    } 
} 

내가 뭘 잘못하고 있니?

답변

14

나는 this thread에 두 가지 솔루션을 발견 :

  1. 는 "복사 항상"는
  2. 은 "사용 배포"를 확인합니다 (Problems with DeploymentItem attribute 참조)에 배포 파일의 "출력 폴더에 복사"속성을 설정 Local.testsettings 파일의 설정 (Problems with DeploymentItem attribute 참조)

희망이 있습니다.

+0

도움 주셔서 감사합니다. 나는 항상 "Copy"를 설정했다. 테스트 설정을 사용하여 배포를 완료했습니다. 이번에 DeplyomentAttribute를 사용하려고 생각했습니다. –

4

향후 참조를 위해 VS 2015를 사용하여 알아 챘습니다. 배포 항목 속성에서 지정하는 경로는 빌드 출력 (디버그 폴더)과 관련이 있어야합니다. 폴더 구조가 "UnitTesting \ TestData \ Test.xml"인 경우 DeploymentItem은 DeploymentItem (".. \ .. \ TestData \ Test.xml")이어야합니다. 이 경우 TestData 폴더는 UnitTesting 프로젝트에 포함될 필요가 없습니다 .

관련 문제