由于Specflow测试而构建失败

时间:2015-11-24 17:15:50

标签: c# msbuild specflow azure-devops

当我们不忽略specflow测试时,Visual Studio Team Services构建中的构建失败。我们所有的测试都返回一个http状态代码401 auth fail,当实际期望200或422等时。这只发生在我们的Visual Studio Team Services构建中,当这些测试在本地运行时它们全部通过。我们在specflow测试中指定了用户名和密码,它们是硬编码的,那么为什么在Team Services上构建时这不起作用或失败?

E.g。

2015-11-24T16:50:48.9936518Z ##[error]Error Message:

2015-11-24T16:50:48.9936518Z ##[error]     Expected: 200

2015-11-24T16:50:48.9936518Z ##[error]  But was:  401

2015-11-24T16:50:48.9936518Z ##[error]

2015-11-24T16:50:48.9936518Z ##[error]Stack Trace:

2015-11-24T16:50:49.0092775Z ##[error]at Test.Specifications.GetImageByIdSteps.ThenTheResultShouldBe(Int32 p0) in C:\a\1\s\Web\Web.Test\Specifications\GetImageByIdSteps.cs:line 36

2015-11-24T16:50:49.0092775Z ##[error]at lambda_method(Closure , IContextManager , Int32 )

2015-11-24T16:50:49.0092775Z ##[error]at TechTalk.SpecFlow.Bindings.BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)

2015-11-24T16:50:49.0092775Z ##[error]at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStepMatch(BindingMatch match, Object[] arguments)

2015-11-24T16:50:49.0092775Z ##[error]at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(StepInstance stepInstance)

2015-11-24T16:50:49.0092775Z ##[error]at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnAfterLastStep()

2015-11-24T16:50:49.0092775Z ##[error]at TechTalk.SpecFlow.TestRunner.CollectScenarioErrors()

2015-11-24T16:50:49.0092775Z ##[error]at Web.Test.Specifications.GetImageByIdFeature.ScenarioCleanup() in C:\a\1\s\Web\Web.Test\Specifications\ImageGetImage.feature.cs:line 0

2015-11-24T16:50:49.0092775Z ##[error]at Web.Test.Specifications.GetImageByIdFeature.GetImage(String imageId, String userName, String password, String http_Status_Code, String[] exampleTags) in C:\a\1\s\Web\Web.Test\Specifications\ImageGetImage.feature:line 12

1 个答案:

答案 0 :(得分:1)

这种情况正在发生,因为连接字符串的转换发生在发布而不是构建上。因此,在构建它时,服务器无法访问在我的本地连接字符串上声明的连接(因为转换没有发生)。我假设在构建时,连接字符串会发生转换。情况并非如此,转换仅在发布时发生。