如何在每次测试运行时重新部署,重新创建数据库 [英] How to re-deploy, re-create database on each test run
问题描述
当前,我正在使用Visual Studio 2012 RC和SQL Server 2012 RTM.
Currently I'm using Visual Studio 2012 RC and SQL Server 2012 RTM.
我想知道如何为每次测试运行重新部署/重新创建测试数据库.
I'd like to know how to re-deploy/re-create a test database for each test run.
请记住,我有一个使用Visual Studio 2012模板的SQL Server数据库项目.
Keep in mind I've a SQL Server database project for the database using Visual Studio 2012's template.
实际上,我不确定我的想法,但是 .testsettings 文件具有设置和清除脚本.这是要走的路吗?例如,一个PowerShell脚本读取数据库项目生成的脚本并针对数据库执行该脚本?
Actually I'm not very sure about an idea I got in my mind, but .testsettings file has Setup and cleanup scripts. Is this the way to go? For example, a PowerShell script reading the database project generated script and executing it against the database?
我想有更好的方法可以做到这一点,这应该是一个即用的解决方案,但是我忽略了它,并且 Google 并不能帮助我找到正确的解决方案.
I guess there're better ways of doing that and it should be an out-of-the-box solution but I ignore it and Google doesn't help me in finding the right solution.
推荐答案
如上所述,您可能想使用VS 2012 .Local.testsettings>安装和清理脚本来创建/拆除SQL Server数据库.
As mentioned you'll probably want to use the VS 2012 .Local.testsettings > Setup and Cleanup scripts to create / tear down you SQL Server database.
对于该脚本,由于您正在使用SSDT项目,因此您可能希望将Powershell与.dacpac一起使用(而不仅仅是T-SQL脚本).这是链接一些示例代码-特别是您可能想看看'Deploy-Dac'命令.
For the script you may want to use powershell with a .dacpac (rather than just a T-SQL script), since you are using a SSDT project. Here's a link to some example code - in particular you may want to take a look at the 'Deploy-Dac' command.
如果您不熟悉.dacpacs作为SSDT创建的数据库项目的(生成)输出,请查看此参考资料
If you are unfamiliar with .dacpacs as the (build) output of SSDT-created database projects, take a look at this reference link.
这篇关于如何在每次测试运行时重新部署,重新创建数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!