如何在每次测试运行时重新部署、重新创建数据库 [英] How to re-deploy, re-create database on each test run

查看:30
本文介绍了如何在每次测试运行时重新部署、重新创建数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我使用的是 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.

对于脚本,您可能希望使用带有 .dacpac 的 powershell(而不仅仅是 T-SQL 脚本),因为您使用的是 SSDT 项目.这是一个链接一些示例代码 - 特别是您可能想查看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屋!

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