Automate SQL unit testing using the command line

Unit Test for SQL Server supports the Command line interface allowing you to automate your unit testing processes using the command line.

  1. Open the Command Prompt.

    Note

    To run the Command Line in Windows 10:

    From the Desktop Mode

    • Move the mouse cursor to the exact lower left corner until the desktop shortcuts menu appears.
    • Right-click to see the shortcut menu and than click Run.

    From the Charms Bar

    • Move your mouse to the upper right corner until the Charms Bar appears.
    • Select Apps from the list and type ‘run’ in the search box.
    • Click Run from the search results.

    Use Windows + R Shortcut Keys

    • In desktop mode, press the Windows + R keys, to show the Run command line.
    • In the window that opens, type cmd and press Enter.
  2. Navigate to the unittest.com file, located in dbForge Unit Test for SQL Server installation folder on your PC, and press SPACEBAR.

  3. Type the arguments (actions you want to run) in the Command Prompt. You can do this in two ways:

  • Type all the arguments directly in the Command Prompt, for example, to install the tSQLt framework on a database:
/testsupport /install_tsqlt:y /connection:"Data Source=SQLlast;Integrated Security=False;User ID=yourusername; Password=yourpassword; Initial Catalog=AdventureWorks2019"
  • Type the path to a previously generated file with required command-line arguments (see below how to prepare the file), for example:
/argfile:"D:\file_name.txt"

Type the additional parameters that are not specified in the file into the Command Prompt, for example:

\unittest.com /argfile:file_name.txt /testsupport /rewritereport:y

Tip

To see a quick help on the arguments available in the command line, type the following:

\unittest.com /?

Press Enter to run the process.

Prepare a file with command-line arguments

To run a job from the command line, first, specify a switch.

/testsupport

Next, you need to specify the required parameters, for example, a connection string:

/testsupport /connection:"Data Source=SQLlast;Integrated Security=False;User ID=yourusername; Password=yourpassword; Initial Catalog=AdventureWorks2019"

To install tSQLt framework on the database before executing tests, use /install_tsqlt:true:

/testsupport /connection:"Data Source=SQL_SERVER;Initial Catalog=TEST_DB;User ID=yourusername;Password=yourpassword" /class:"test_class01" /install_tsqlt:true

To execute all tests in the database and uninstall the tSQLt framework, use: /uninstall_tsqlt:true

/testsupport /connection:"Data Source=SQL_SERVER;Initial Catalog=TEST_DB;User ID=yourusername;Password=yourpassword" /uninstall_tsqlt:true

To generate and save a report file, specify the file name and location. For example:

/outreport:"D:\report.txt"

To learn how you can involve dbForge Unit Test in the development process, feel free to watch this video.