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.

  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=admin; Password=admin; 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=admin; Password=admin; 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=USER_NAME;Password=PASS" /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=USER_NAME;Password=PASS" /uninstall_tsqlt:true

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

/outreport:"D:\report.txt"