Search code examples
azure-devopsazure-pipelinesazure-devops-hosted-agent

Using docker image with database or LocalDB for integration tests in Azure DevOps


I'm currently investigating how to best implement integration tests. We use C# to build Azure Functions and have unit-tests in-place (runs as part of the build in Azure DevOps).

Next step is to include integration tests for integrating with MS SQL Server (we use Dapper). I have done some research and concluded that using an in-memory database is not the way to go (different engine). Therefore I'm wondering if it is possible to create a Docker image with a SQL Server or instantiate LocalDB(https://github.com/Microsoft/azure-pipelines-image-generation/blob/master/images/win/Vs2017-Server2016-Readme.md does not list SQL Server Express or LocalDB), run scripts against it (to setup the database to the desired state) and then run integration tests (using MSTest)?


Solution

  • Okay so sqllocaldb.exe is installed on the VS2017 build agents. I ended up using (and improving) https://github.com/ritterim/automation-sql to wrap sqlocaldb.exe in C#.