Class Assert
Each static method in this class takes a parameter called message
, which is
a string literal identifier used to aggregate assertions.
Antithesis generates one test property per unique message
. This test property will be named message
in the triage report.
Each static method also takes a parameter called details
, which is an ObjectNode
reference of optional additional information provided by the user to add context for assertion failures.
The information that is logged will appear in the logs
section of a triage report.
Normally the values in details
are evaluated at runtime.
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Assert thatcondition
is true every time this function is called, and that it is called at least once.static void
alwaysOrUnreachable
(boolean condition, String message, com.fasterxml.jackson.databind.node.ObjectNode details) Assert thatcondition
is true every time this function is called.static void
rawAssert
(Assert.AssertType assertType, String displayType, String className, String functionName, String fileName, int beginLine, int beginColumn, String id, boolean condition, String message, com.fasterxml.jackson.databind.node.ObjectNode details, boolean hit, boolean mustHit) This is a low-level method designed to be used by third-party frameworks.static void
Assert that a line of code is reached at least once.static void
sometimes
(boolean condition, String message, com.fasterxml.jackson.databind.node.ObjectNode details) Assert thatcondition
is true at least one time that this function was called.static void
unreachable
(String message, com.fasterxml.jackson.databind.node.ObjectNode details) Assert that a line of code is never reached.
-
Constructor Details
-
Assert
public Assert()Default constructor
-
-
Method Details
-
always
public static void always(boolean condition, String message, com.fasterxml.jackson.databind.node.ObjectNode details) Assert thatcondition
is true every time this function is called, and that it is called at least once. The corresponding test property will be viewable in theAntithesis SDK: Always
group of your triage report.- Parameters:
condition
- the condition being asserted. Evaluated at runtime.message
- a unique string identifier of the assertion. Provides context for assertion success/failure and is intended to be human-readable. Must be provided as a string literal.details
- additional details that provide greater context for assertion success/failure. Evaluated at runtime.
-
alwaysOrUnreachable
public static void alwaysOrUnreachable(boolean condition, String message, com.fasterxml.jackson.databind.node.ObjectNode details) Assert thatcondition
is true every time this function is called. The corresponding test property will pass even if the assertion is never encountered.The corresponding test property will be viewable in the
Antithesis SDK: Always
group of your triage report.- Parameters:
condition
- the condition being asserted. Evaluated at runtime.message
- a unique string identifier of the assertion. Provides context for assertion success/failure and is intended to be human-readable. Must be provided as a string literal.details
- additional details that provide greater context for assertion success/failure. Evaluated at runtime.
-
sometimes
public static void sometimes(boolean condition, String message, com.fasterxml.jackson.databind.node.ObjectNode details) Assert thatcondition
is true at least one time that this function was called. (If the assertion is never encountered, the test property will therefore fail.) This test property will be viewable in theAntithesis SDK: Sometimes
group.- Parameters:
condition
- the condition being asserted. Evaluated at runtime.message
- a unique string identifier of the assertion. Provides context for assertion success/failure and is intended to be human-readable. Must be provided as a string literal.details
- additional details that provide greater context for assertion success/failure. Evaluated at runtime.
-
unreachable
public static void unreachable(String message, com.fasterxml.jackson.databind.node.ObjectNode details) Assert that a line of code is never reached. The corresponding test property will fail if this method is ever called. (If it is never called the test property will therefore pass.) This test property will be viewable in theAntithesis SDK: Reachability assertions
group.- Parameters:
message
- a unique string identifier of the assertion. Provides context for assertion success/failure and is intended to be human-readable. Must be provided as a string literal.details
- additional details that provide greater context for assertion success/failure. Evaluated at runtime.
-
reachable
public static void reachable(String message, com.fasterxml.jackson.databind.node.ObjectNode details) Assert that a line of code is reached at least once. The corresponding test property will pass if this method is ever called. (If it is never called the test property will therefore fail.) This test property will be viewable in theAntithesis SDK: Reachability assertions
group.- Parameters:
message
- a unique string identifier of the assertion. Provides context for assertion success/failure and is intended to be human-readable. Must be provided as a string literal.details
- additional details that provide greater context for assertion success/failure. Evaluated at runtime.
-
rawAssert
public static void rawAssert(Assert.AssertType assertType, String displayType, String className, String functionName, String fileName, int beginLine, int beginColumn, String id, boolean condition, String message, com.fasterxml.jackson.databind.node.ObjectNode details, boolean hit, boolean mustHit) This is a low-level method designed to be used by third-party frameworks. Regular users of the assertions class should not call it.This is primarily intended for use by adapters from other diagnostic tools that intend to output Antithesis-style assertions.
Be certain to provide an assertion catalog entry for each assertion issued with
rawAssert()
. Assertion catalog entries are also created usingrawAssert()
, by setting the value of thehit
parameter to false.Please refer to the general Antithesis documentation regarding the use of the Fallback SDK for additional information.
- Parameters:
assertType
- must be a valid Assertion.AssertType valuedisplayType
- one of "Always", "AlwaysOrUnreachable", "Sometimes", "Reachable", "Unreachable"className
- the name of the package and class containing this assertionfunctionName
- the name of the method containing this assertionfileName
- the name of the source file containing this assertionbeginLine
- the source line number where the assertion is locatedbeginColumn
- the source column number where the assertion is locatedid
- the unique text associated with the assertioncondition
- the condition being asserted. Evaluated at runtime.message
- a unique string identifier of the assertion. Provides context for assertion success/failure and is intended to be human-readable.details
- additional details that provide greater context for assertion success/failure. Evaluated at runtime.hit
- true if the assertion has been evaluated, false if the assertion is being added to the assertion catalogmustHit
- true if the assertion is expected to be evaluated at least once, otherwise false
-