|
|||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||
See:
Description
| Class Summary | |
| Assert | Wrapper for assertion functions. |
| Ensure | Wrapper for output requirement functions. |
| Require | Wrapper for input requirement functions. |
| Error Summary | |
| AssertionError | Thrown when an assertion fails. |
| InputRequirement | Thrown when an input requirement (Require) fails. |
| OutputRequirement | Thrown when an output requirement (Ensure) fails. |
Assertions are a means of checking program correctness. They are not a means of checking for user error (that's robustness, two doors down.).
Require is used to enforce the validity of the inputs to a routine or method.
As such, they form the executable part of that routine's input specification. In the
real world, where there is no time to write specs, the Require are often part of
the specification.
When a Require fails, it indicates that the caller has violated the rules of usage
for the routine. In short, a Require means: the routine will make sure these things
are true before any work will get done.
Use Require to specifiy the restrictions on the inputs to a function.
For example, if a function took in an signed integer called count that
was assumed to be at least MIN_VALUE, use Require.condition(count>=MIN_VALUE).
Require is also used to validate the state of the structure/file scope/abstraction
in as much as the caller has visibility to that state. For example,
if there was a function, called ReadyForInput, that is visible
to the caller, and a function assumed that the state was ReadyForInput,
the function should have a Require.condition(ReadyForInput()) at the top of the
body. Require should be the first executable statements of a function.
Ensure are used to verify that the outputs of a routine or method conform to the
interface specifications for that routine or method. In a pinch (i.e. reality check),
the Ensure themselves serve as part of a routine's specification.
When an Ensure fails, it indicates that the routine (not the caller) is at fault, and
has not kept its promises. In short, an Ensure means: The routine promises that these
things will be true on exit.
Use Ensure to indicate what the state or value of the function outputs.
In Java, there is no language defined way to refer to the value
returned by a function. A useful convention is that the variable be named
"returned". In this way, an Ensure, such as Ensure.condition(foo != 0)
becomes Ensure.condition(returned != 0), and this implies that the function
will never return a 0 value.
Assert are used within the body of a routine to verify internal states. They
have nothing to do with the interface specifications. When an Assert fails, it
indicates a problem within the routine.
Use Assert to specify what the state of the structure/file scope/abstraction
should be at a given point/line in a function. For example, after searching
for a menu item, it is assumed to be between 1 and the number of items
in the menu, use Assert.condition((iItem >= 1) && (iItem <= iItemCount)).
/SourceTree/core/error
19 March 2001 - Ed Stauff - initial version reviewed by Test Automation team.
|
|||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||