Automate SQL Stored Procedure Unit Testing for Code First Approach Part - 2

In the last post we have learnt how to create SQL Server Database project and how to create unit test project using that. Also we have learnt how to add unit test case and add pre test and post test scripts.If you have missed anything please follow the below link.
Link : https://codespate.blogspot.com/2020/07/automate-sql-stored-procedure-unit.html
Today we are going to add the unit test and database project to azure pipeline and automate the build and test.I am following the ef code first approach.So the database deployment will be handled by the migrations/migrator. This sql server project is useless for me. But why we have added that here is to simplify the unit test creation.

So the plan is
  1. Application and the database will be deployed through the existing pipeline
  2. We need to modify the build pipeline to build the sql unit test project
  3. After release only we can see the latest changes in the database.So we need to add the testing after the release only.
  4. Thus we need to create another stage for testing and after release that will be triggered
  5. To execute the test we need the test dlls so we need to archive that from the build and need to use in the test stage.
So to build the test project I need to modify  my build pipeline slightly.My existing pipeline tasks will look like below.
To use unit test project dlls after release I need to archive those from here and then need to extract and use it in the test stage. After adding the archive task, my pipeline tasks will look like this.
Next we need to modify our release pipeline. After release I am going to add another stage to perform the test. My release pipeline structure will look like below.
In the test stage I am extracting the test dlls from artifacts and using vstest task to run the test.
Here I am using the replace token task to replace the values from the app.config connection string and point to my dev database.After the test execution I can see the results.
Thats it.We have automated the unit testing for the stored procedures. While building the unit test and database project ,I have faced some issues and I have added a post on how to fix those.Please check that also.
Link :https://codespate.blogspot.com/2020/07/fix-sql-unit-test-build-failure-in.html

Comments

Popular posts from this blog

Fix Sql Unit Test build failure in Azure Devops pipeline

Fix Cannot determine the organization name for this 'dev.azure.com' remote URL Issue Visual Studio 2019

How to call content page method from master page in ASP.NET