Click here to Skip to main content
15,881,588 members
Articles / Database Development

Autogenerate Unit Tests For Your Database Objects - Visual Studio 2019 & 2022 (amd64) Extension

Rate me:
Please Sign up or sign in to vote.
4.90/5 (5 votes)
4 Jan 2023CPOL4 min read 9.8K   8   16   7
Features and functionalities associated with Autogenerate DB Unit Test app
In this article, you will get a detailed overview of the features and functionalities that are associated with the Autogenerate database Unit test app.

Table of Contents


This document provides a detailed overview of the features available to a user within the Autogenerated DB Unit Tests (ADUT) application. It describes the processes and actions involved in automatically generating Unit Tests for your respective database objects:

  1. Stored Procedures (inc. multiple outputs)
  2. Inline Functions
  3. Scalar Functions
  5. Computed Fields

Download Visual Studio 2019 Extension 


Download Visual Studio 2022 Extension

Once downloaded, double click to install (close any instances of Visual Studio you may have open). After the installation has completed, when you next open Visual Studio the Extension will be installed and ready to use.


The user guide provides a comprehensive step-by-step guide to using the new ADUT application. It is intended to convey the significant features which are available to the end user.


The scope of this document is to conveniently convey the features of the ADUT parsing application.

Initiating the Autogenerate DB Unit Tests Extension

From within your Visual Studio IDE, select the Extensions → Database Unit test Generator → Configuration Panel menu option, to open the configuration panel.

Image 1

Database Settings Dialog

Here, the user will enter the connection string to the (staging) database they wish to generate unit tests against. The user has the ability to test their connection string, within the Control Panel.

Select the database type, test framework and the programming language of choice.

Image 2

NB: If any of the stored procedures are to output multiple datasets, the connection string attribute must be adorned with the MultipleActiveResultSets=True (see the connection string above).

The connection-string credentials must be associated with the View Definition group within the database, so that the application can refactor the database objects from its schema(s).

There is also the option to associate SQL scripts with the Unit Test’s Initialize and Teardown methods associated with the Class and\or individual Unit Test methods.

The Load option will allow the user to retrieve a previously saved control panel setting (the project can be saved at the Generate Unit Test dialog stage).

Once the user has clicked on the Connect button, the database schema will be parsed, and the respective database objects will be displayed for the user to select.

Database Objects Dialog

Image 3

From here, the user may wish to create unit tests for all the available database objects or granularly select a specific set of objects to generate unit tests against.

The checkbox at the bottom, is for Computed fields within any database table, this will generate a test per computed field per table.

By clicking the Generate Unit Tests button, the tests will be automatically generated and displayed within the editor window.

Multiple Database Schema Objects

The application will pick up the different schema that the connection string has access to, so you can target certain aspects of the database with the unit tests.

Image 4

Unit Test Editor Window

Image 5

From here, the user can copy the complete generated unit test class to the clipboard or highlight a specific unit test and copy.

NB: The application will generate dummy values to be passed into the stored procedures, the user will have to reconfigure the actual values that need to be passed in for the unit tests to function properly, when the assertions are performed.

The user has the functionality to navigate back and re-select database objects to generate unit tests for. The tests can be simply copied into the Unit Test class project, which can then be executed using the Test Explorer.

Visual Studio Test Explorer

Below, you can see the unit tests copied from the Autogenerated DB editor window into a C# MSTest class.

NB: For Visual Studio 2022, you will need to add the NuGet package System.Data.Sqlclient for your MSTest project to compile.

Image 6

Using the Test Explorer, the user can verify that their tests are working as expected and then check the Unit Test project into their code repository which can be executed against their continuous integration pipeline.

Image 7

Saving Project

Clicking on the Save button will prompt the user to select a destination folder to save the project file (which can be loaded later).

Image 8

Example of Saved Project File

Below, you can see the properties that get saved from the application, the user can reimport these control panel settings again when they want to regenerate the tests again, against the database.

Image 9


  • 26th December, 2022: Initial version


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Ireland Ireland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

SuggestionSupport for Visual Studio 2022? Pin
Arttu Y.5-Jan-23 20:00
Arttu Y.5-Jan-23 20:00 
GeneralRe: Support for Visual Studio 2022? Pin
Bert O Neill6-Jan-23 15:09
mvaBert O Neill6-Jan-23 15:09 
GeneralRe: Support for Visual Studio 2022? Pin
Bert O Neill6-Jan-23 15:13
mvaBert O Neill6-Jan-23 15:13 
PraiseRe: Support for Visual Studio 2022? Pin
Arttu Y.6-Jan-23 20:06
Arttu Y.6-Jan-23 20:06 
QuestionHow is this installed? Pin
Cliff Buckley5-Jan-23 6:18
Cliff Buckley5-Jan-23 6:18 
AnswerRe: How is this installed? Pin
Bert O Neill5-Jan-23 8:10
mvaBert O Neill5-Jan-23 8:10 
GeneralRe: How is this installed? Pin
Cliff Buckley5-Jan-23 9:00
Cliff Buckley5-Jan-23 9:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.