简体   繁体   English

在 Azure Devops yaml 构建管道中运行时如何为 SSDT 单元测试指定连接详细信息

[英]How to specify connection details for SSDT unit tests when run in Azure Devops yaml build pipeline

I am using SSDT unit tests for my database project.我正在为我的数据库项目使用 SSDT 单元测试。 They run no problem from Visual Studio.它们从 Visual Studio 运行没有问题。

I would like these tests to run when I run my build pipeline on Azure DevOps, but when it is unable to connect.我希望在 Azure DevOps 上运行构建管道时运行这些测试,但无法连接时。 I get the following error:我收到以下错误:

System.Data.SqlClient.SqlException: System.Data.SqlClient.SqlException: 110003;Invalid user or password. System.Data.SqlClient.SqlException: System.Data.SqlClient.SqlException: 110003;无效的用户或密码。

The yaml for my test is as follows:我测试的yaml如下:

- task: VSTest@2
  inputs:
        testSelector: 'testAssemblies'
        testAssemblyVer2: |
          **\*test*.dll
          !**\*TestAdapter.dll
          !**\obj\**
        searchFolder: '$(System.DefaultWorkingDirectory)'

Is there anything in particular that needs to go in the app.config file to get this to work?有什么特别需要进入 app.config 文件才能使其工作的吗? Note: I'm using SQL authentication.注意:我正在使用 SQL 身份验证。

If the SSDT unit tests connects to the database server on your local machine, the azure devops pipeline will fail, for the hosted agents cannot communicate with your local machine.如果 SSDT 单元测试连接到本地计算机上的数据库服务器,azure devops 管道将失败,因为托管代理无法与本地计算机通信。

In this case you should create a self-hosted agent on your local machine, and run your pipeline on the self-hosted agent by defining the pool as your local agent pool in yaml pipeline.在这种情况下,您应该在本地计算机上创建一个自托管代理,并通过将池定义为 yaml 管道中的本地代理池来在自托管代理上运行您的管道。

If you are using other cloud database server like azure sql server.如果您使用其他云数据库服务器,如 azure sql server。 You can check if the connectionString in App.config is correct, and provide the correct User ID and Password .您可以检查 App.config 中的 connectionString 是否正确,并提供正确的User IDPassword The connectionString in app.config file is like below example app.config 文件中的 connectionString 如下例所示

在此处输入图片说明

If you want to avoid storing sensitive information in a connection string in app.config.如果您想避免在 app.config 中的连接字符串中存储敏感信息。 You can store the connectionString in a secret variable in your pipeline.您可以将 connectionString 存储在管道中的秘密变量中。

And use tokens connectionString="#{sqlDbTestConnectionString}#" in app.config in place of real connection strings.并在 app.config 中使用令牌connectionString="#{sqlDbTestConnectionString}#"代替真正的连接字符串。

Then add replace token task before VsTest task in your pipeline to replace the tokens #{sqlDbTestConnectionString}# in app.config with the real connectionString defined in secret variable.然后在管道中的 VsTest 任务之前添加替换令牌任务,以将 app.config 中的令牌#{sqlDbTestConnectionString}#替换为秘密变量中定义的真实 connectionString。

You can check this blog for more information.您可以查看此博客以获取更多信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Azure DevOps Build Pipeline 中运行测试 - Run tests in Azure DevOps Build Pipeline 如何从Build DevOps向特定开发人员发送详细的电子邮件,因为来自Build管道的单元测试失败? - How to send a detailed email to specific developer from Azure DevOps on failure of unit tests from a Build pipeline? 从 azure devops 管道运行项目测试 - run project tests from azure devops pipeline 在 Azure DevOps 上,我找不到解释如何自动运行单元测试项目作为 .NET Core 构建管道的一部分的示例 - On Azure DevOps, I cannot find an example that explains how to automatically run unit test projects as part of the build pipeline for .NET Core Azure DevOps 管道 - 为 UWP 项目配置单元测试 - Azure DevOps Pipeline - Configure Unit Tests for UWP Project Azure DevOps 管道单元测试与库依赖不起作用 - Azure DevOps pipeline unit tests with library dependency not working Azure Devops - MSTest - 如果我的单元测试失败,我如何使构建失败,但在集成测试失败时继续(带有警告/通知) - Azure Devops - MSTest - How can I fail a build if my unit tests fail, but continue (with warning/notification) when integration test fail C# 单元测试在 Azure DevOps 中运行,但不在 Visual Studio 中运行 - C# Unit Tests run in Azure DevOps but not in Visual Studio 如何在Yaml灯具中为RoR单元测试指定相对日期 - How to specify a relative date in yaml fixtures for RoR unit tests 尝试将 UWP 单元测试作为构建管道的一部分或使用 vstest 运行时“无法激活应用程序” - "Failed to activate app" when trying to run UWP unit tests as part of a build pipeline or using vstest
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM