Table of Contents |
---|
Structure
A MettleCI Unit Test Specification (often abbreviated ‘Spec’') is a YAML-formatted file which uses a grammar modelled loosely on the Gherkin syntax of a testing tool called Cucumber. The overall structure follows the Gherkin pattern…
Code Block | ||
---|---|---|
| ||
given: # This source of input data when: # The specified job is executed with these parameter values then: # Expect the Job to produce data that looks like this |
Given
The given
section defined a list of stage
properties nodes (or sparseLookup
nodes, see below) defining input links whose values you wish to replace with test data.
...
Each link is specified using a combination of stage
and link
properties (to uniquely identify an incoming link which supplies data to your Job) and a path
property node to identify the test data CSV file containing the test data that is to be injected on that incoming link.
Sparse Lookup sources
When an input source is used with a Sparse Lookup stage then rather than using the stage
node to specify the input you will use the sparseLookup
node.
...
See this page for more information.
When
The when
node specifies which job will be executed during testing as well as any parameters (including job macros) that affect the data produced by the job.
Code Block | ||
---|---|---|
| ||
when: job: KeyGeneratorExample # The DataStage Job with which this test spec is associated parameters: DSJobStartDate: 2012-01-15 # Run the test using this value for the DSJobStartDate macro DSJobStartTime: 11:05:01 # Run the test using this value for the DSJobStartTime macro paramStartKey: 100 # Run the test using this value for the paramStartKey Job parameter |
...
Then
The then
section associates unit test data files with each of your Job’s input links.
...
Similar to the Given
section, each link in the Then
section is specified using a combination of stage
and link
properties nodes (to uniquely identify an outgoing link which produces data from your Job) and a path
property node to identify the test data CSV file containing the test data that is to be injected on that incoming link.
Cluster keys
The cluster
property node is used to assist MettleCI’s resource management when using high volumes of test data. Setting a Cluster Key will prompt MettleCI to split the actual output and expected output using multiple, smaller subsets (based on the supplied keys) before the data is compared. Data is split such that each subset will only contain records that have the same values for all columns that make up the Cluster Key. In general, cluster keys should only be used when necessary, and not specified by default. Read more about the using the cluster
property node in High Volume Unit Tests.
Row count comparisons
You can configure as test to only compare output row counts, rather than the content of those rows, by setting the checkRowCountOnly
property node to true
.
Code Block | ||
---|---|---|
| ||
then: - stage: Output link: Write1 path: Output-Write1.csv checkRowCountOnly: true |
See this page for more information.
Excluding columns from unit tests
You can omit selected columns from the output comparison by listing those columns them under an ignore
property node for the relevant output.
Code Block | ||
---|---|---|
| ||
then: - stage: Transform link: Output path: Transform-Output.csv ignore: - CREATION_DATE - LAST_UPDATED |
See this page for more information.
Test Specification Types
Job Run Mode | Test Specification | Description | |||
---|---|---|---|---|---|
‘Given’ section | 'When' section | Test Specification‘Then’ section | Description|||
Normal | |||||
Ignored | Job is executed normally with no MettleCI no test harness intervention. | ||||
Unit Test Interception | |||||
✅ Specified | ✅ Specified | ✅ Specified | ? EmptyInterception is executed normally:
| ||
∅ Unspecified | ✅ Specified | ✅ Specified | Fail?Sources are accessed without change and Job output is compared to specified Expected result. | ||
⛔️ Specifies non-existent files | ✅ Specified | ✅ Specified | Causes test execution failure. | ||
✅ Specified | ✅ Specified | ? Empty | Fail?∅ Unspecified | Causes test execution failure as there are no value Expected results to test against, so this is not a valid test. | |
✅ Specified | ✅ Specified | ⛔️ Specifies non-existent files | Re-baseline’s expected test output. See Capturing a Baseline Test Result. | ||
Unit Test Execution | |||||
✅ Supplied | ✅ Supplied | ✅ Supplied⛔️ Empty | Test is executed normally. | ||
∅ Unspecified | ✅ Supplied | ✅ Supplied | No input test data specified so the Job’s normal input operations are permitted to read from upstream data sources. Output is compared to an expected output test data file. See an example here. | ||
⛔️ Specifies non-existent files | ✅ Specified | ✅ Specified | Test fails to execute and Job aborts. | ||
✅ Supplied | ✅ Supplied | ⛔️ Empty∅ Unspecified | Input test data is injected into your jobs but no output test data is supplied for comparison so the Job’s normal output operations are permitted to write to downstream data stores. No output comparison is performed. | ||
✅ Specified | ✅ Specified | ⛔️ Specifies non-existent files | Test fails to execute and Job aborts. |
Test specification patterns
Include Page | ||||
---|---|---|---|---|
|