error

ETLUnit 3.9.6

 

Draft in Progress

This document is a draft and is under development.

 

Description

  • Force an error to be thrown from a test method.  For debug purposes.

Attributes

List of error() Attributes

 

message:  - >> TYPE:  string

error-id:  - >> TYPE:  string

Individual error() Attributes

message:

  • The message to throw with the error.
  • This message may show up in the log.

error-id:

  • The error-id string is arbitrary.  It may show up in the CLI (Command Line Interface) when you run the test to provide information about where the error came from.  It may also show up on the summary page report next to the test method.
  • The convention is to make this error-id all capitals, with words separated by underscores.  For instance, FORCED_ERROR or WORKFLOW_SHOULD_HAVE_FAILED.

 

Usage

When etlunit test reaches the error() operation, an error is thrown and processing of that test method stops.

 

Example of error() operation

@Test

errorOperationExample()

{

log(

message: 'Not annotated with Error',

log-file-name: 'test_me.log',

log-classifier: 'anyClassifier'

);

error(

message:'Forced error message for debugging',

error-id:'ETLUNIT_FORCED_ERROR'

);

}

 

 

userme > te #errorOperationExample
Processing [1] tests
class experiment.test_me   -------------------------------------------------------
1/1        .errorOperationExample
      ETLUNIT_FORCED_ERROR
  Caused an error                                                             E[1]
Tests run: 1, Errors: 1, Time elapsed: 0.174 sec

 

Note that the error ID that I specified in the error() operation appeared in the CLI under the name of my test method.

Run the report...

 

userme > r

 

. . . and you may see the value of error-id next to the method name.

 

The error caused by the error() operation may be caught by specifying the value of the error-id attribute in the @Test annotation's expected-error-id attribute.

 

Example of catching error thrown by error operation

@Test(expected-error-id: 'ETLUNIT_FORCED_ERROR')

errorOperationCaughtExample()

{

log(

message: 'Not annotated with Error',

log-file-name: 'test_me.log',

log-classifier: 'anyClassifier'

);

error(

message:'Forced error message for debugging',

error-id:'ETLUNIT_FORCED_ERROR'

);

}

 

The content of the test method hasn't changed, but because we specified an expected-error-id, this time the test passed when run from the Command Line Interface:

 

userme > te #errorOperationCaught
Processing [1] tests
class experiment.test_me   -------------------------------------------------------
1/1        .errorOperationCaughtExample
  Passed                                                                      P[1]
Tests run: 1, Successes: 1, Time elapsed: 0.161 sec