Define and execute data test cases
On this page
Data test cases describe input and expected output, generate a test procedure and record execution results.
Use an isolated test warehouse
The PreDelete and PostDelete paths generate a command that attempts to truncate tables across the connected database, excluding CFG.SNAPSHOTS. This is broader than clearing only tables named in the test. Do not run these options against a warehouse whose data must be retained.
The workflow also executes configured pre/post SQL. Neither the UI nor this guide promises automatic rollback of all test effects.
Procedure
- Create a test case and select its input and expected-output tables.
- Define sample data and use Preview to inspect parsed definitions.
- Configure pre/post scripts and cleanup only for the isolated target.
- Save to generate/store the test script.
- Use Validate to apply the saved test procedure when appropriate.
- Run the test and inspect error and result tabs.
- Open Test log to compare repeated runs.
Save changes to pre/post scripts and Cleanup before running the test. The execution command regenerates the procedure using the settings already held by the test definition.
The runner executes a generated CFG.TEST_* procedure on the DWH connection. A test is reported successful when there is no error message and no nonempty result table. Mismatch result sets indicate differences; they are not normal successful query output.
Definition syntax
A definition is a line-based list of SQL value expressions, not a CSV file or a complete INSERT statement:
- The first nonblank, non-comment line is a comma-separated list of column names. Use physical column names, optionally enclosed in square brackets.
- Each following line supplies one comma-separated expression list in the same order. Do not add SELECT, VALUES or parentheses around the entire row.
- Use SQL literals and expressions: quote text, use
NULLfor a null value, and supply expressions compatible with the selected columns. - Blank lines are ignored.
#starts a comment, including after values on the same line.
Illustrative definition for a table with ID and Name columns:
[ID], [Name]
1, N'Alpha'
2, N'O''Brien' # second row
3, NULL
The input path turns the values into an INSERT with SELECT/UNION ALL SELECT. The expected-output path prepares temporary expected data and then compares it with the selected table. These examples describe generated syntax; they have not been executed against a sample repository.
Repeating rows
Place a repetition prefix at the start of a value line:
| Prefix | Counter values |
|---|---|
{3} |
1, 2, 3 |
{2-4} |
2, 3, 4 |
{2-6,2} |
2, 4, 6 |
Bounds are inclusive. The step is relative to the starting value, not to zero. Use positive integers with an end greater than or equal to the start. The implementation normalizes zero bounds to 1, treats steps of 0 or 1 as unrestricted increments, and does not provide a descending-range syntax. Do not rely on those normalization details to validate a definition.
[ID], [Name]
{2-6,2} @int, N'Item ' + @str
This describes rows (2, 'Item 2'), (4, 'Item 4') and (6, 'Item 6'). Each value line has its own bounds; the counter does not continue from the preceding line. Repeated overlapping ranges can therefore generate duplicate keys.
Generated values
Use the lowercase spellings below. Replacement is case-sensitive.
| Token | Generated value for counter N |
|---|---|
@int |
N as a number |
@str |
N converted to nvarchar(10) |
@uid |
N converted through binary(16) to a uniqueidentifier; it is not a random NEWID() |
@now |
SQL Server's current date at midnight, converted to datetime |
@now-d, @now-w, @now-m, @now-y |
Midnight today minus N days, weeks, months or years |
@now+d, @now+w, @now+m, @now+y |
Midnight today plus N days, weeks, months or years |
A value line containing @int, @str or @uid activates replacement even without a prefix; it then uses N = 1. A date token alone does not activate replacement. Use an explicit prefix for date-only expressions:
[EffectiveDate], [Name]
{1} @now-d, N'Yesterday'
Dates are evaluated when the generated SQL runs. Input and expected expressions are not a stored shared clock value; use fixed dates if a test must be reproducible across dates or midnight boundaries.
Parser limitations and preview
The owner confirms that this minimal format is intentional for now. SQL-aware quote handling and literal hash support are possible future improvements, not currently promised features.
The parser is not SQL-aware when removing comments or replacing tokens. A literal containing # is cut at that character, and a token inside quoted text can be replaced when the line activates iteration. Supply tokens as expressions outside quotes. For a literal hash character, an expression such as N'Item' + NCHAR(35) avoids the comment marker in the definition itself.
Keep each row on one physical line. The header must contain simple, distinct column names, not expressions or identifiers containing commas. The parser does not perform complete SQL or type validation; malformed expressions and mismatched value counts can fail later.
The editor preview calls the parser without table metadata. It shows a query-shaped preview, not the final table-aware INSERT, identity handling or expected/actual comparison. Inspect the generated test procedure as well before execution. Use small repetition ranges first; no interactive row-count safety limit is established by this parser.
Generated execution order
The generated procedure performs these steps in order:
- Run PreDelete cleanup if enabled.
- Update snapshots through the warehouse snapshot procedure.
- Execute PreScript after macro expansion.
- Insert the defined input data.
- Execute the dependency actions selected between input and expected-output objects.
- Compare actual data with the expected definitions.
- Execute PostScript after macro expansion.
- Run PostDelete cleanup if enabled.
PostScript therefore cannot prepare data for the comparison that precedes it. Cleanup is emitted at the end of the procedure, not in a guaranteed finally block: an earlier execution error can prevent it from running.
Which columns and keys are compared
The definition's column list determines the compared columns. Columns omitted from that list are not assertions about the table's remaining values.
The comparison selects its key as follows:
- If the table contains the field configured by
HIST_ID_FIELDNAME, that field takes precedence. - Otherwise, the comparison uses the table's primary-key columns in key order.
- Key-based comparison is used only when the expected definition includes the complete selected key. Otherwise, comparison falls back to
EXCEPTin both directions.
For example, if the configured surrogate key is present in a history table but the expected definition includes only a business key and a value, the comparison does not match history versions by that business key. Include the surrogate key to exercise key-based matching.
| Comparison result | Meaning |
|---|---|
| Expected only | An expected key has no matching actual row. |
| Actual only | An actual key has no matching expected row. |
| Mismatch / Expected and Mismatch / Actual | The key matches, but selected non-key values differ. Equal non-key values are displayed as NULL in these diagnostic rows. |
| Mismatched rows in expected / actual | The fallback set comparison found rows on only one side. |
Key matching uses equality, while non-key comparison explicitly checks NULL/value differences. Use non-null unique keys for key-based expectations. A NULL in the mismatch display can mean an unchanged value suppressed for readability; inspect the expected/actual pair and the definition together.
Neither path is a general duplicate-count assertion. In particular, EXCEPT compares sets and ignores duplicate multiplicity. Add an explicit count check when row counts or duplicates are part of the requirement.
Interpreting a run
The runner treats any nonempty result table as a failed test, including a result set returned by a custom script. Avoid returning informational SELECT results from PreScript or PostScript unless they are intended to signal failure. Inspect both errors and all result tables before interpreting the log.
Interrupt requests cancellation. Check the target state afterwards; cancellation is not a universal undo operation. The execution log stores user, timestamp, success and serialized results/errors.
For a safe conceptual scenario, see testing a small flow.
Batch execution
In the test list, mark the tests with Run, then start execution. Clicking the Run column header toggles the Run flag for all repository tests in the handler, not just selected rows. The runner saves pending changes first and reports that there is no script to execute if no test is marked.
Selected tests run sequentially. The query has no explicit ordering, so do not make one test depend on another test running first. Each test can perform its own cleanup and pre/post scripts; tests share the configured DWH connection target, not a batch-wide isolated database or rollback boundary.
For each marked test, the runner:
- Regenerates and saves the test script.
- Applies it to the DWH using CREATE OR ALTER PROCEDURE.
- Executes the generated test procedure on the DWH connection.
- Stores the returned result/error JSON as the test's latest result.
- Inserts a historical log record and refreshes navigation.
Generation and procedure-application errors are saved as failed results in both the latest test result and the historical batch log. The batch continues to the next test unless cancellation was requested. A failure to save repository changes can still terminate the outer run. Run tests is disabled while a batch is active.
Interrupt behavior
Interrupt requests cancellation of the executing SQL command. The current test is recorded as unsuccessful with a cancellation message, then the batch stops before starting the next test. No placeholder records are created for tests not started. Earlier completed changes are not rolled back. Procedure generation/application remains synchronous; cancellation does not make that phase asynchronously interruptible.
Historical logs and current limitations
Historical records contain the test, serialized results, errors, repository user, success flag and IsBatch. Batch records share the timestamp captured at the start of the run. The navigation summary groups batch records by that timestamp and reports success only when all stored flags in the group are successful. Opening the summary loads those records; opening an individual log loads it by ID. The viewer displays errors and nonempty result tables.
The latest result on a test is overwritten on a subsequent execution; historical entries are inserted separately. There is no separate batch-run identifier in this grouping path. A summary represents the stored records, not proof that every selected test reached execution.
The success flag is calculated independently for each test from its execution status, errors and returned rows. Any failed test makes the overall batch unsuccessful. Older historical records are not repaired by this change; inspect their stored errors/results when investigating previous runs.