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

问题描述 投票:0回答:1

我正在为我的数据库项目使用SSDT单元测试。它们在Visual Studio中运行没有问题。

我希望在Azure DevOps上运行构建管道,但无法连接时运行这些测试。我收到以下错误:

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

我测试的Yaml如下:

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

要使此功能正常工作,需要在app.config文件中添加一些特别的内容吗?注意:我正在使用SQL身份验证。

unit-testing azure-devops sql-server-data-tools
1个回答
0
投票

如果SSDT单元测试连接到本地计算机上的数据库服务器,则由于托管代理无法与本地计算机进行通信,azure devops管道将失败。

在这种情况下,您应该在本地计算机上create a self-hosted agent,并通过将池定义为yaml管道中的本地代理池,在自托管代理上运行管道。

如果您使用的是其他云数据库服务器,例如Azure SQL服务器。您可以检查App.config中的connectionString是否正确,并提供正确的User IDPassword。 app.config文件中的connectionString类似于以下示例

enter image description here

如果要避免将敏感信息存储在app.config的连接字符串中。您可以将connectionString存储在管道的secret variable中。

并在app.config中使用令牌connectionString="#{sqlDbTestConnectionString}#"代替实际的连接字符串。

然后在管道中的VsTest任务之前添加replace token task,以用秘密变量中定义的实际connectionString替换app.config中的令牌#{sqlDbTestConnectionString}#

您可以检查this blog了解更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.