Main Content

matlab.unittest.constraints.Constraint class

Package: matlab.unittest.constraints

Fundamental interface class for comparisons

Description

The Constraint interface class is the means by which matlab.unittest constraints encode comparison logic and the corresponding diagnostic information. Every comparison that conditionally can produce a failure inherits from the Constraint interface class.

Classes deriving from the Constraint interface class must provide a means to determine if a given value satisfies the constraint. To do this, implement the satisfiedBy method, which includes the definition of the underlying comparison logic. Classes deriving from the Constraint class also must provide a diagnostic for any given actual value. The testing framework uses the diagnostic when it encounters a qualification failure. To do this, implement the getDiagnosticFor method.

In exchange for meeting these requirements, all Constraint implementations are easily used with all qualification types through the verifyThat, assertThat, assumeThat, or fatalAssertThat methods. The qualifications use the comparison and diagnostic knowledge contained within the constraints. Also, the constraints can be used in situations where a test failure is not wanted, but the testing framework needs to reuse the comparison logic. For example, a constraint implementation may want to use the logic defined inside of another constraint. Since the constraint can interact with the other constraint directly, it can use the logic without the potential of causing a qualification failure.

Methods

getDiagnosticForProduce diagnostic for compared value
satisfiedByDetermine whether value satisfies constraint

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects.