liveBook · Manning

Test script

As explained in 100 SQL Server Mistakes and How to Avoid Them

A test script is executable test code that invokes the functionality under test with specified inputs.

Mistake: treating setup or cleanup as the test itself. A test script executes the code module with specified inputs; pretest scripts prepare data, while posttest scripts remove it. section 7.5

A practical unit test separates its responsibilities:

  • Use the pretest script to populate required tables or otherwise prepare the environment. section 7.5
  • Use the test script to invoke the code module with values such as CampaignID 27587, Budget 10, and Detailed 1. section 7.5
  • Use the posttest script to delete created data, such as a sales order, after execution. section 7.5

Checking results

A test can verify scalar values—1.7876, 195, and 6.85—and require 42 rows in a second result set. Remove the default inconclusive condition before adding these checks. section 7.5

Figure 7.6 Creating a unit test

Use the unit-test editor to select the test script and configure its result conditions. section 7.5

How 100 SQL Server Mistakes and How to Avoid Them covers it

How deep it goes
Explains execution, parameter entry, result conditions, and separation from setup and cleanup scripts.
Examples
Uses CampaignID 27587, Budget 10, Detailed 1, scalar checks, and a 42-row result-set requirement.
What it assumes
Assumes a SQL Server instance and testing project, while providing editor templates for the test code.
What you can do after
Apply it via Visual Studio to invoke code and validate scalar outputs and result-set row counts.
How it connects
Connects test scripts with unit testing, pretest scripts, posttest scripts, stored procedures, result sets, and row-count conditions.

Also explained in

Compare how 2 books explain test script →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 SQL Server Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.