TFS构建的SQL服务器单元测试 [英] SQL server unit test on TFS build

查看:72
本文介绍了TFS构建的SQL服务器单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个由TFS构建的解决方案和SQL服务器单元测试应该在每个构建上运行。测试部分还包含一个数据库项目
,它应该在测试运行之前部署到localDB。 SQL服务器单元测试项目的配置是:

< configSections> 
< section name =" SqlUnitTesting" type =" Microsoft.Data.Tools.Schema.Sql.UnitTesting.Configuration.SqlUnitTestingSection,Microsoft.Data.Tools.Schema.Sql.UnitTesting,Version = 12.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a" />
< section name =" entityFramework" type =" System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089" requirePermission = QUOT假QUOT; />
<! - 有关Entity Framework配置的更多信息,请访问http://go.microsoft.com/fwlink/?LinkID=237468 - >< / configSections>
< connectionStrings>
< add name =" SnapDBContext" connectionString =" Data Source =(localdb)\ MSSQLLocalDB; Initial Catalog = SampleDatabase; Integrated Security = SSPI;"的providerName = QUOT; System.Data.SqlClient的" />
< / connectionStrings>
< SqlUnitTesting>
< DatabaseDeployment DatabaseProjectFileName =" .. \..\..\..\Database\SampleDatabase.sqlproj"配置="调试和QUOT; />
< DataGeneration ClearDatabase =" true" />
< ExecutionContext Provider =" System.Data.SqlClient" ConnectionString =" Data Source =(localdb)\ MSSQLLocalDB; Initial Catalog = SampleDatabase; Integrated Security = True; Pooling = False"的CommandTimeout = QUOT; 30英寸; />
< PrivilegedContext Provider =" System.Data.SqlClient" ConnectionString =" Data Source =(localdb)\ MSSQLLocalDB; Initial Catalog = SampleDatabase; Integrated Security = True; Pooling = False"的CommandTimeout = QUOT; 30英寸; />
< / SqlUnitTesting>
< entityFramework>
< defaultConnectionFactory type =" System.Data.Entity.Infrastructure.LocalDbConnectionFactory,EntityFramework" />
< providers>
< provider invariantName =" System.Data.SqlClient" type =" System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer" />
< / providers>
< / entityFramework>

一切都在我的本地机器上工作正常,但在TFS上失败并出现错误:


从配置文件中读取SQL Server单元测试设置时发生错误。单击测试项目,从SQL菜单打开
SQL Server测试配置对话框,将设置添加到对话框,然后重建项目。


这些人认为测试在TFS 2013上运行良好但在升级到TFS 2015我们开始出现此错误。试过不同的解决方案在这里和互联网上找到了
,但没有任何帮助。我错过了什么?谢谢。



解决方案

嗨安德鲁,


感谢您发布此处。


根据错误消息,似乎构建代理程序服务帐户无法正确读取配置文件。


因此,请确保服务帐户首先拥有访问目标SQL Server的权限。


此外,如果您正在使用VSTest VNext,这意味着VSTest无法读取配置文件,VSTest可以使用.testsettings文件告诉它自定义单元测试执行环境的各个方面。


所以,你可以尝试根据设置创建.testsettings文件,然后在构建定义中指定
运行设置文件,然后再次尝试


请参考类似的线程进行故障排除:



最佳R egards。


We has a solution which is being built by TFS and SQL server unit tests which should be run on each build. The tests part also consists of a Database project which should be deployed to localDB before tests are running. The config for SQL server unit test project is:

<configSections>
        <section name="SqlUnitTesting" type="Microsoft.Data.Tools.Schema.Sql.UnitTesting.Configuration.SqlUnitTestingSection, Microsoft.Data.Tools.Schema.Sql.UnitTesting, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
  <connectionStrings>
    <add name="SnapDBContext" connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=SampleDatabase;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
  </connectionStrings>
    <SqlUnitTesting>
        <DatabaseDeployment DatabaseProjectFileName="..\..\..\..\Database\SampleDatabase.sqlproj" Configuration="Debug" />
        <DataGeneration ClearDatabase="true" />
        <ExecutionContext Provider="System.Data.SqlClient" ConnectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=SampleDatabase;Integrated Security=True;Pooling=False" CommandTimeout="30" />
        <PrivilegedContext Provider="System.Data.SqlClient" ConnectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=SampleDatabase;Integrated Security=True;Pooling=False" CommandTimeout="30" />
    </SqlUnitTesting>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

Everything work fine on my local machine but on TFS it fails with an error:

An error occurred while SQL Server unit testing settings were being read from the configuration file. Click the test project, open the SQL Server Test Configuration dialog box from the SQL menu, add the settings to the dialog box, and rebuild the project.

The guys assumes that the tests worked fine on TFS 2013 but after the upgrading to TFS 2015 we started to get this error. Tried different solutions found here and over the internet but nothing helps. What am I missing? Thank you.

解决方案

Hi Andrew,

Thank you for posting here.

According to the error message, it seems that the build agent service account cannot read the configuration files correctly.
So, please make sure the service account has the permission to access the target SQL Server first.

Besides, If you are using VSTest in VNext, that means the configuration file can't be read by VSTest, VSTest can use a .testsettings file to tell it to customize various aspects of the unit test execution environment.

So, you can try to create a .testsettings file based on the settings, then specify the Run Settings File in build definition, then try it again.

Please reference the similar threads for the troubleshoot:

Best Regards.


这篇关于TFS构建的SQL服务器单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆