_@Test
Description
- Configures a method as a test in the ETLUnit class file.
Attributes
Attribute Name | Required? | Possible Values | Info |
---|---|---|---|
expected-error-id | No |
|
|
expected-failure-id | No |
|
|
expected-failure-ids | No |
|
|
Location in the test class file
Immediately above a method. This annotation changes the method type to a 'test' method. It will execute when a user issues the 'test
' command in the Command Line Interface.
Examples
@Test
example
class bool_conversion_test {
@Test
testBounds() {
stage(
file: 'bool_conversion_src.txt',
variable-name: 'inputfile1'
);
//Run workflow
execute(
workflow: 'wkf_BOOL_CONVERSION_TEST',
folder: 'SHARED_EDW'
);
//asssertions
assert(
target: 'BOOL_CONVERSION_TGT',
reference-file-type: 'bool',
source-file: 'output'
);
}
}
@Test
example with expected-error-id
@Test
nullLineLengthGp1() {
set(variable: 'inputgrouptest', value: '1');
stage(
file: 'fwq_qpt_data_format_nullFieldWidth.txt',
destination-name: 'fwq_qpt_data_format_src.txt'
);
execute(
workflow: 'wkf_TEST_FORMAT_QPT_DATA_FWQ',
folder: 'SHARED_QPT_PET'
);
}
When the test is run without expected-error-id
(above), the test errors out (below).
userme > te #Gp1 Processing [1] tests class [default].fwq_format_qpt_data_test --------------------------------------- 1/1 .nullLineLengthGp1 ERR_EXECUTE_WORKFLOW Caused an error E[1] Tests run: 1, Errors: 1, Time elapsed: 30.111 sec
@Test(expected-error-id: 'ERR_EXECUTE_WORKFLOW')
nullLineLengthGp1() {
set(variable: 'inputgrouptest', value: '1');
stage(
file: 'fwq_qpt_data_format_nullFieldWidth.txt',
destination-name: 'fwq_qpt_data_format_src.txt'
);
execute(
workflow: 'wkf_TEST_FORMAT_QPT_DATA_FWQ',
folder: 'SHARED_QPT_PET'
);
}
When the test is run with the correct expected-error-id
(above), the test passes (below).
userme > te #Gp1 Processing [1] tests class [default].fwq_format_qpt_data_test --------------------------------------- 1/1 .nullLineLengthGp1 Passed P[1] Tests run: 1, Successes: 1, Time elapsed: 6.851 sec
@Test
example with expected-failure-id
@Test
forceFailure()
{
log(
message: 'Testing fail operation',
log-file-name: 'test_me.log',
log-classifier: 'failClassifier'
);
fail(
message:'Failure message',
failure-id: 'FORCED_FAILURE'
);
}
When the test is run without expected-failure-id
(above), the test fails (below).
userme > te #forceFailure Processing [1] tests class experiment.test_me ------------------------------------------------------- 1/1 .forceFailure FORCED_FAILURE Failed F[1] Tests run: 1, Failures: 1, Time elapsed: 0.18 sec
@Test(expected-failure-id: 'FORCED_FAILURE')
forceFailure()
{
log(
message: 'Testing fail operation',
log-file-name: 'test_me.log',
log-classifier: 'failClassifier'
);
fail(
message:'Failure message',
failure-id: 'FORCED_FAILURE'
);
}
When the test is run with the correct expected-failure-id
(above), the test passes (below).
userme > te #forceFailure Processing [1] tests class experiment.test_me ------------------------------------------------------- 1/1 .forceFailure Passed P[1] Tests run: 1, Successes: 1, Time elapsed: 0.162 sec
@Test
example with expected-failure-ids
@Test(
expected-error-id: 'ERR_EXECUTE_WORKFLOW',
expected-failure-id: 'BOZO WAS HERE'
)
@LogAssertion(
expected-log: {
assertion-mode: 'contains-pattern',
classifier: 'targetFiles',
failure-id: 'BOZO WAS HERE',
expected-log-expression: '#xxx',
log-name-pattern: 'fwq_qpt_data_format_tgt_1'
}
)
lineLengthNegativeGp1() {
set(variable: 'inputgrouptest', value: '1');
stage(
file: 'fwq_qpt_data_format_NegativeFieldWidth.txt',
destination-name: 'fwq_qpt_data_format_src.txt'
);
fail(message: 'deliberate failure', failure-id: 'MARLO_WAS_HERE');
execute(
workflow: 'wkf_TEST_FORMAT_QPT_DATA_FWP',
folder: 'SHARED_QPT_PET'
);
}
When the test is run without expected-failure-ids
(above), the test fails (below).
userme > te #gp1 Processing [1] tests class [default].exp_format_pos_data_test --------------------------------------- 1/1 .lineLengthNegativeGp1 MARLO_WAS_HERE BOZO WAS HERE FAIL_EXPECTED_ASSERTION FAIL_EXPECTED_EXCEPTION Failed F[4] Tests run: 1, Failures: 4, Time elapsed: 7.208 sec
The test failures piled up.
It turns out in this case that adding the MARLO_WAS_HERE failure to the list of expected failures will cause the test to pass.
So you can mask these problems by adding one additional expected-failure-id
. But to do that, you need to use expected-failure-ids
, the list version of the expected-failure-id
attribute.
@Test(
expected-error-id: 'ERR_EXECUTE_WORKFLOW',
expected-failure-ids: [
'MARLO_WAS_HERE',
'BOZO WAS HERE'
]
)
@LogAssertion(
expected-log: {
assertion-mode: 'contains-pattern',
classifier: 'targetFiles',
failure-id: 'BOZO WAS HERE',
expected-log-expression: '#xxx',
log-name-pattern: 'fwq_qpt_data_format_tgt_1'
}
)
lineLengthNegativeGp1() {
set(variable: 'inputgrouptest', value: '1');
stage(
file: 'fwq_qpt_data_format_NegativeFieldWidth.txt',
destination-name: 'fwq_qpt_data_format_src.txt'
);
fail(message: 'deliberate failure', failure-id: 'MARLO_WAS_HERE');
execute(
workflow: 'wkf_TEST_FORMAT_QPT_DATA_EXP',
folder: 'SHARED_QPT_PET'
);
}
When the test is run with the correct expected-failure-ids
(above), the test passes (below).
userme > te #gp1 Processing [1] tests class [default].fwq_format_qpt_data_test --------------------------------------- 1/1 .lineLengthNegativeGp1 Passed P[1] Tests run: 1, Successes: 1, Time elapsed: 8.59 sec