_@Error
Description
- Annotation on a test method.
- Causes an 'error' type of exception to be thrown from the test method.Â
- Will appear in the CLI as an
ERR_UNSPECIFIED
, unless the@Test
annotation on the same test method has an attributeexpected-error-id
, with 'ERROR_UNSPECIFIED
as its value. @Error
Throws an exception after the last executable line in the method executes.- If an error occurs during the method, causing it to stop and throw an error, that error will show in the log, but not on the command line.
ERR_UNSPECIFIED
will override whatever that error may be. - Useful for debugging.
Attributes
Attribute Name | Required? | Possible Values | Info |
---|---|---|---|
description | Yes |
|
|
Location in the test class file
Before a test method.
Examples
The following test will pass, because the error is "caught."Â
The @Test
annotation has an expected-error-id of 'ERR_UNSPECIFIED
.'
Â
@Error gets caught by @Test
@Test(expected-error-id: 'ERR_UNSPECIFIED')
@Error(description: 'Demonstration of the @Error annotation.')
executeError()
{
log(
message: 'Annotated with Error',
log-file-name: 'test_me.log',
log-classifier: 'anyClassifier'
);
}
Â
The following test will produce an error, because there is nothing to catch the error forced by the @Error
annotation.
Â
@Error does not get caught
@Test
@Error(description: 'Demonstration of the @Error annotation.')
executeError()
{
log(
message: 'Annotated with Error',
log-file-name: 'test_me.log',
log-classifier: 'anyClassifier'
);
}
Â