由于 Specflow 测试,构建失败
Build failing because of Specflow tests
Visual Studio 中的构建当我们不忽略 specflow 测试时,Team Services 构建失败。当实际期望 200 或 422 等时,我们所有具有 http 状态代码 401 身份验证的测试 return 都失败了。这只发生在我们的 Visual Studio Team Services 构建中,当这些测试在本地 运行全部通过。我们在 specflow 测试中指定了用户名和密码,它们是硬编码的,那么为什么在 Team Services 上构建时这不起作用或验证失败?
例如
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\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\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\s\Web\Web.Test\Specifications\ImageGetImage.feature:line 12
发生这种情况是因为连接字符串的转换发生在发布时而不是构建时。因此,在构建它时,服务器无法访问在我的本地连接字符串上声明的连接(因为转换没有发生)。我假设在构建时转换发生在连接字符串上。事实并非如此,转换仅在发布时发生。
Visual Studio 中的构建当我们不忽略 specflow 测试时,Team Services 构建失败。当实际期望 200 或 422 等时,我们所有具有 http 状态代码 401 身份验证的测试 return 都失败了。这只发生在我们的 Visual Studio Team Services 构建中,当这些测试在本地 运行全部通过。我们在 specflow 测试中指定了用户名和密码,它们是硬编码的,那么为什么在 Team Services 上构建时这不起作用或验证失败?
例如
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\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\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\s\Web\Web.Test\Specifications\ImageGetImage.feature:line 12
发生这种情况是因为连接字符串的转换发生在发布时而不是构建时。因此,在构建它时,服务器无法访问在我的本地连接字符串上声明的连接(因为转换没有发生)。我假设在构建时转换发生在连接字符串上。事实并非如此,转换仅在发布时发生。