Support Center

Name is required.
Email address is required.
Invalid email address
Answer is required.
Exceeding max length of 5KB

Deploying a DB prior to unit test execution

Dylan Beattie Jan 10, 2014 02:05AM AEDT

Hey there!

I have some integration tests that run against a SQL Server localdb database - my development app talks to a full SQL instance on localhost, but the integration tests all talk to (localdb)\v11.0

It would be really handy if I could run the ReadyRoll database deployment against localdb as part of my test fixture setup, so we're always testing the code against the latest set of migrations.

Is this possible? The test code is all C# and NUnit is our test framework.

Thanks!

Dylan

Up 1 rated Down
Daniel Nolan Jan 10, 2014 02:19PM AEDT ReadyRoll Agent

Hi Dylan,

We currently don’t have an API for deploying databases with ReadyRoll, however you could call out to SQLCMD to perform the database deployment as part of your test fixture setup.

Firstly, you’ll need to enable SQLCMD packaging within your database project (under Outputs in Project Settings). Then, ensure that your unit test project has a dependency on the database project, so that the package is built before the tests are executed.

In your test fixture setup, make a call to SQLCMD:
sqlcmd.exe -E -S (localdb)\v11.0 -i “…\MyDbProject\bin\Debug\MyDbProject_Package.sql” -v DatabaseName=MyDatabase

This will deploy any pending migrations, creating the database as necessary. To start with a clean database, you may like to add a separate call to SQLCMD to drop the database prior to deployment.
sqlcmd -E -S (localdb)\v11.0 -Q “IF DB_ID(‘MyDatabase’) IS NOT NULL DROP DATABASE [MyDatabase]”

So that the package artifact is included along with your test results, you may like to copy the “MyDbProject_Package.sql” file to your test project, eg. as part of the “.testsettings” Deployment configuration in Visual Studio.

Best Regards,

Daniel

This question has received the maximum number of answers.

readyroll.support@red-gate.com
http://assets2.desk.com/
false
readyrollsql
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
false
Invalid characters found
/customer/en/portal/articles/autocomplete