The Test Class
Draft in Progress
This document is a draft and is under development.
Creating a New Test Class
How to Create a Test Class
Create an ETLUnit test class with any ASCII compatible text editor.
Test Class File Naming
- The name of the file containing the test class should end with the extension, '
.etlunit
.' - The file name does not have to have the same name as the test class.
- The file may contain multiple test classes.
Test Class Content Format
The syntax used in ETLUnit test classes is proprietary to ETLUnit. In appearance, it appears to be a cross between an object oriented programming language like Java, and JSON syntax. SEE the Test Class Declaration example below.
Syntax for a Test Class
Sample Test Class
Below is a sample ETLUnit test class. It runs tests against Informatica work flows.
@JoinSuite(name:'bucket_v2')
@JoinSuite(name:'aud')
@JoinSuite(name:'omc')
@Database(id: 'edw', modes: ['src'])
class gap_bucket
{
@Test
columnsloadinorder_bucket()
{
stage(
file: 'FF_BUCKET_V2.txt',
classifier: 'source'
);
stage(
source: 'BUCKET_V1_GAP',
connection-id: 'edw',
target-table: 'BUCKET'
);
execute(
workflow: 'wkf_GAP_FILLER_CREATE_V1_BUCKET_DELTA',
folder: 'EDW_QPT_BUCKET',
context:
{
edw-connection-src: 'informatica.connections.edw.src',
edw-connection-tgt: 'informatica.connections.edw.tgt'
}
);
assert(
source-file: 'FF_BUCKET_V1_DELTA_20130312',
reference-file-type: 'gap_bucket'
);
}
@Test
Filter_bucket_Detail()
{
stage(
file: 'FF_BUCKET_V2.txt',
classifier: 'source'
);
stage(
source: 'BUCKET_DETAIL_V1_FIL_GAP',
connection-id: 'edw',
target-table: 'BUCKET_DETAIL'
);
execute(
workflow: 'wkf_GAP_FILLER_CREATE_V1_BUCKET_DETAIL_DELTA',
folder: 'EDW_QPT_BUCKET',
context:
{
edw-connection-src: 'informatica.connections.edw.src',
edw-connection-tgt: 'informatica.connections.edw.tgt'
}
);
assert(
target: 'FF_BUCKET_DETAIL_FIL_V1_DELTA_20130312',
source-file:'FF_BUCKET_DETAIL_V1_DELTA_20130312',
reference-file-type: 'gap_bucket_detail'
);
}
}
Parts of a Test Class
Annotations
Annotations may be placed at the file, class or method levels. Annotations begin with the '@' symbol. Here is an example.
@Database(id: 'master')
@Database(id:'edw-pet')
class extract_master_to_edw_pet
{
@Test
colInOrder()
{
}
}
Test Class Declaration
A single ETLUnit test file may have any number of test classes in it. It is good form to try to stick to only one test class per test file, and to use the same name for both the file and the declared test class.
The class declaration requires:
- The 'class' keyword
- The name of the class
- Delimiting curly braces
@Database(id: 'master')
@Database(id:'edw-pet')
class extract_master_to_edw_pet
{
@Test
colInOrder()
{
}
}
Test Method Declaration
The test method sets apart a single 'test.' A test class may have any number of test methods.
@Database(id: 'master')
@Database(id:'edw-pet')
class extract_master_to_edw_pet
{
@Test
colInOrder()
{
}
}
Operations
Some common test operations are:
- stage() - - Sets up data, typically to be used by the execute().
- set() - - Sets a variable.
- execute() - - Represents the process being tested.
- assert() - - Test an assumption against the actual artifact or condition.
- assert-log() - - Test an assumption against the actual log file.
@Database(id: 'master')
@Database(id:'edw-pet')
class extract_master_to_edw_pet
{
@Test
colInOrder()
{
stage()
{
source: 'EXT_MASTER_TO_EDW_PET_tPLANT_GEO_CODE',
target-table: 'tPlant_Geo_Code',
connection-id: 'master',
target-schema: 'dbo'
};
set()
{
variable: 'population_time',
value: '2013-01-01 00:00:00'
};
execute()
{
folder: 'TDN_ANALYTICS',
workflow: 'wkf_EXTRACT_MASTER_TO_EDW_PET'
};
assert()
{
source-table: 'tPlant_geo_code',
connection-id: 'edw-pet',
source-schema: 'master_dbo',
target: 'EXT_MASTER_TO_EDW_PET_TPLANT_GEO_CODE_PET'
};
assert-log(
classifier: 'sessionLog',
log-name-pattern: '^s_m_EXTRACT_.*\\.log\\.[\\d]+\\.[\\d]+$',
expected-log-expression: 'The session completed with [0] row transformation errors.',
failure-id: 'LOG_ENTRY_NOT_FOUND'
);
}
}
Comments
There are two ways to include comments in an ETLUnit test class file.
// The single line comment stays entirely on one line.
stage() // It may even appear on the same line as executable code,
{ // but only to the RIGHT of the executable code.
source: 'DATA_TO_STAGE',
target-table: 'TABLE_IN_THE_DATABASE'
}
/* The multi-line comment, however, may appear
on several contiguous lines.
You're welcome! In case you were thinking, "Thank you!"
*/
Dig deeper