2013-11-04 1 views
4

VS2012에서 테스트 파일 클래스와 동일한 폴더에 저장 한 다른 xml/text 파일을 사용하는 (MS) 단위 테스트가 있습니다. 내가 한 검사를 실행할 경우테스트를 실행 한 후 AppDomain.CurrentDomain.BaseDirectory가 변경됩니까?

나는이 파일을 읽을 때, 작동, (해당 AppDomain.CurrentDomain.BaseDirectory + "파일")

을 File.OpenRead를 사용하여 이러한 파일을 엽니 다.

모든 테스트를 한 번에 실행하면 BaseDirectory가 다른 경로 (TestResults/Deploy/currentdatetime/Out에 있음)를 반환하고 분명히 그 파일을 찾을 수 없습니다.

어떻게해야합니까?

감사합니다.

+0

시도를 [\ [DeploymentItem \ ("당신의 상대 파일 경로"@)] 각 시험 [1] 속성. 또한 모든 파일을 프로젝트에 추가하고 속성을 CopyToOutputDirectory를 "CopyAlways"로 설정해야한다고 생각합니다. http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.deploymentitemattribute.aspx – Spock

+0

1. 작동하지 않았 음 :(2. 이미 복사 했으므로 한 번에 여러 테스트를 실행할 때 기반 디렉토리의 경로가 변경됨 – user2713516

+0

DeploymentItem으로 무엇을 장식 했습니까? 테스트 클래스 또는 테스트 메서드? – Elena

답변

-1

잘 작동하지 않았으며 Google이 생각하지 않는 것처럼 보입니다.

해결 방법은 같은 경로 편집 간단했다 :

[ClassInitialize] 
    public static void ClassInitialize(TestContext context) 
    { 
     string deployDir = AppDomain.CurrentDomain.BaseDirectory; 
     string[] rows = deployDir.Split(new string[] { "TestResults" }, StringSplitOptions.None); 
     string projectPath = rows[0].ToString(); 
     _path = projectPath + "newpath\\"; 
    }