Reuse values with variables and chaining
Use {{name}} variables, keep secrets masked, and pass a value from one test to the next.
In short
Write {{name}} in a test's SQL or a parameter value and the environment's variable of that name is used, so one test runs on Local and QA with different values. An Extract rule copies a value from one run into a variable that the next test reads.
Before you start
- Who: variables live in the environment, which Manage on the project changes. Extract rules and chain order are part of a test, so they need Edit.
- Plan: every plan.
- First: decide which values are secret before you extract a password or a token.
Use a variable
- Add the variable to the environment, with a value. Tick "Secret" for passwords and tokens.
- Write {{name}} in the test's SQL or in a parameter value.
- To override it for one run, type a value in "Variables for this run".
Pass a value to the next test
- In test A, add an extraction under "Extract values": Variable invoiceId, From Output parameter, Path NewInvoiceId. Set Chain order 1.
- In test B, set a parameter to {{invoiceId}} and Chain order 2.
- On the Tests board, tick "Run all tests in order (chained)" and press "Run all tests".
Rollback breaks chains Each test is its own transaction. If A rolls back, B will not find the invoice A created. Put the setup in B's Setup SQL, or run A with Commit on a Local, Development or QA database you may change.
Good to know
- An Extract rule can copy a cell, an output parameter, the return value, rows affected or the row count, from a successful run.
- A secret value is encrypted, shown masked in the environment, and masked again wherever a run records its SQL or parameters. An unticked variable is stored as written and appears in run history.
- Extracted values land in the environment, where everyone with access to the project sees them. Mark the variable Secret before you extract a password or token.
If something goes wrong
- "Secret variable '…' needs a value."
- "Secret variable '…' cannot be decrypted with the active data-protection key ring.": enter its value again.
- Test B finds nothing: test A rolled back. See the callout above.
Related
- /help/sql-tester/case-editor
- /help/sql-tester/saving-cases
- /help/sql-tester/connections-and-environments