liveBook · Manning

Test condition

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

A test condition is an assertion that evaluates whether a test result satisfies an expected property.

A test condition asserts that a test result has an expected property. Treat it as part of the test design, not as decoration: a wrong expected value can make correct code appear broken. section 7.5

Configure conditions against the result sets produced by the code under test:

  • Use scalar value conditions to check specific values, such as Column 2 = 1.7876, Column 5 = 195, and Column 6 = 6.85. section 7.5
  • Use a Row Count condition when the expected result is a number of rows; the example expects 42 rows in the second result set. section 7.5
  • Review failures critically: an incorrect expected result or condition can be the defect. section 7.5

A stored-procedure test

A unit test executes a stored procedure that adds a sales order, using CampaignID 27587, Budget 10, and Detailed set to 1. Scalar conditions check returned values, while a Row Count condition checks that the second result set contains 42 rows. section 7.5

Figure 7.6 Creating a unit test

Inspect the test-code windows and configured conditions while building the unit test. section 7.5

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

How deep it goes
Defines scalar and row-count checks, shows configuration and execution, and cautions that a failing condition may itself be incorrect.
Examples
Uses scalar checks for three columns and a row-count check expecting 42 rows from a second result set.
What it assumes
Assumes familiarity with executing SQL code and test parameters while teaching condition types through a concrete stored-procedure test.
What you can do after
Build it from scratch by adding configured scalar-value and row-count conditions to a Visual Studio unit test.
How it connects
Connects unit testing with stored procedures, result sets, parameters, and Test Explorer.

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.