Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database integration tests in Visual Studio Online

I'm enjoying the new Build tool in Visual Studio Online. Allows me to do almost everything that I do my local build server. But one thing that I'm missing is integration database tests: for every build run I re-create test database from scripts and run DB-tests against it.

In Visual Studio Online I can't seem to find any database instance available for my needs.

I have tried creating Azure SQL database (via PowerShell) for every build run and then delete it after the build is complete. But it takes forever (comparing to the rest of the build process) to create a database. And even when PowerShell scripts are done, database is not yet ready to accept requests - I need to constantly check if it is actually ready. So this scenario becomes too complex and not reliable.

Are there other options to do database (SQL Server) integration tests in Visual Studio Online?

Update: I think I'm not very clear of what I need - I need a free (very cheap) SQL Server instance to connect to that runs on build agent in VSO. Something like SQL Express or SQL CE or LocalDB, where I can connect to and re-create database to run C# tests against. Re-creating database or running tests is not a problem, having a valid connection string is a problem.

Update Oct 2016: I've blogged about how I do integration testing in VSTS

like image 697
trailmax Avatar asked Jan 05 '16 00:01

trailmax


People also ask

Are database tests integration tests?

Integration tests focus on testing how separate parts of the program work together. In the context of applications using a database, integration tests usually require a database to be available and contain data that is convenient to the scenarios intended to be tested.

How do I run Mstest in Visual Studio?

Run tests in Test Explorer If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.

Can Nunit be used for integration testing?

ASP.NET Core has an extremely useful integration testing framework, in the form of the NuGet package Microsoft.

How do I create a web test in Visual Studio?

Open Visual Studio. On the start window, choose Create a new project. On the Create a new project page, type web test into the search box, and then select the Web Performance and Load Test Project [Deprecated] template for C#. Choose Next.


1 Answers

The TFS build servers come with MSSQL Server 2012 and MSSQL Server 2014 LocalDBs preinstalled.

Source: TFS Service - Software on the hosted build server

So, just put the following one-liner into your solution's post-build event to create a MYTESTDB LocalDB instance for your needs. This will allow you to connect to (LocalDB)\MYTESTDB an run the database integration tests just fine.

"C:\Program Files\Microsoft SQL Server\120\Tools\Binn\SqlLocalDB.exe" create "MYTESTDB" 12.0 -s

Source: SqlLocalDB Utility

like image 73
Roman Pletnev Avatar answered Oct 18 '22 03:10

Roman Pletnev