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






4.90/5 (5 votes)
Features and functionalities associated with Autogenerate DB Unit Test app
Table of Contents
- Introduction
- Initiating the Autogenerate DB Unit Tests Extension
- Database Settings Dialog
- Database Objects Dialog
- Unit Test Editor Window
- Visual Studio test Explorer
- Saving Project
- History
Introduction
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:
- Stored Procedures (inc. multiple outputs)
- Inline Functions
- Scalar Functions
- Views
- Computed Fields
Download Visual Studio 2019 Extension
OR
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.
Purpose
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.
Scope
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.
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.
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
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.
Unit Test Editor Window
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.
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.
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).
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.
History
- 26th December, 2022: Initial version