2016-10-12 3 views
0

TestServer를 설정하고 요청을 작성하고 응답의 유효성을 검사하는 작업 단위 테스트를하고 있습니다.mstest.exe에서 OWIN TestServer를 시작하십시오.

Visual Studio Test Explorer에서 단위 테스트를 실행하면 잘 작동합니다. TestServer가 설정되고 요청이 작성되고 올 Y 른 응답이 리턴됩니다.

명령 줄 (CI 서버에서)에서 동일한 코드를 실행할 때 TestServer는 항상 "찾을 수 없음"에 대한 상태 코드를 반환합니다. 다른 예외는 없습니다. 명령 줄에서 OWIN을 시작할 때 추가해야하는 명령이 있습니까? 내가 말했듯이, 테스트가 비주얼 스튜디오 내에서 잘 작동

[TestMethod] 
public async Task GetToken() 
{ 
    using (var server = TestServer.Create<TestStartupConfiguration>()) 
    { 
     var response = await server.CreateRequest("/TokenUrl").And(x => x.Content = new FormUrlEncodedContent(new[] 
     { 
      new KeyValuePair<string, string>("username", user.UserName), 
      new KeyValuePair<string, string>("password", user.Password), 
      new KeyValuePair<string, string>("grant_type", "password") 
     })).PostAsync(); 

     response.IsSuccessStatusCode.Should().BeTrue("this is the expected return value of an Access Token request"); 
     var responseString = await response.Content.ReadAsStringAsync(); 
     responseString.Should().NotBeNullOrWhiteSpace("the response of an Access Token request should not be empty"); 
    } 
} 

을 그리고 :

MSTest.exe /testcontainer:myTests.dll /resultsfile:testresults.trx 

내 시험 방법은 다음과 같습니다

MSTest.exe 명령은 다음과 같습니다. 그리고 다른 모든 단위 테스트는 명령 줄에서 예상대로 실행됩니다.

고맙습니다.

+0

빌드 설정이 NuGet 패키지를 복원합니까? – toadflakz

답변

0

내 문제에 대한 해결책을 찾았습니다. NotFound 오류는 Unit 테스트로 실행할 때 으로 설정 한 AllowInsecureHttp 속성을 테스트하려는 OAuth 구성이 있었기 때문에 발생했습니다. 나는 이모드 일뿐만 아니라 단위 테스트가 실행 중일 때도 true인지 확인했습니다.

이제 완벽하게 작동합니다.