我有一个工作单元测试,用于设置TestServer,创建请求和验证响应。
当我从Visual Studio测试资源管理器运行那些单元测试时,它们可以很好地工作。设置TestServer,发出请求并返回正确的响应。
当我从命令行(在我们的CI服务器上)运行相同的代码时,TestServer始终返回“未找到”的状态代码。没有其他例外。从命令行启动OWIN时是否需要添加任何特定的命令?
MSTest.exe命令如下所示:
MSTest.exe /testcontainer:myTests.dll /resultsfile:testresults.trx
我的测试方法如下所示:
[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");
}
}
而且,正如我所说,该测试可以在Visual Studio中正常运行。并且所有其他单元测试均按预期从命令行执行。
非常感谢!
我找到了解决我问题的方法。该NotFound
错误来了,因为OAuth的配置,我想测试有AllowInsecureHttp
属性设置为false
一个单元测试运行时。我确信,AllowInsecureHttp
是true
不仅在DEBUG
模式,但也是一个单元测试运行时。
现在,它可以完美运行了。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句