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:
- 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.
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.
From within your Visual Studio IDE, select the Extensions → Database Unit test Generator → Configuration Panel menu option, to open the configuration panel.
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.
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.
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.
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.
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.
Clicking on the Save button will prompt the user to select a destination folder to save the project file (which can be loaded later).
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.
- 26th December, 2022: Initial version