Class Assert
- Namespace
- Antithesis.SDK
- Assembly
- Antithesis.SDK.dll
The Assert class enables defining test properties
about your program or workload.
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 optional JsonObject reference of additional information provided
by the caller to add context to assertion passes and failures. The information that is logged will appear in the logs section of a
triage report.
Null omits details; an explicit empty object is preserved. Argument expressions are evaluated on every call, even when the assertion does not emit.
public static class Assert
- Inheritance
-
Assert
- Inherited Members
Remarks
If you include opaque CLR objects in your assertion details, the SDK may be unable to detect unsupported output from their serializers and emit the corresponding diagnostics.
Methods
Always(bool, string, JsonObject?)
Assert that condition is true every time this method is called, and that it is called at least once
(i.e. the corresponding test property will fail if the assertion is never encountered).
The corresponding test property will be viewable in the Antithesis SDK: Always assertions group of your triage report.
public static void Always(bool condition, string message, JsonObject? details = null)
Parameters
conditionboolThe condition being asserted.
messagestringA unique string identifier of the assertion. Provides context for assertion passes and failures and is intended to be human-readable. Must be provided as a string literal or as a reference to a publicly accessible const field.
detailsJsonObjectOptional additional details. Null omits details; an empty object is preserved. Serialization failures produce an antithesis_error record and the assertion still emits without details.
AlwaysGreaterThanOrEqualTo<T>(T, T, string, JsonObject?)
AlwaysGreaterThanOrEqualTo(left, right, ...) is mostly equivalent to Always(left >= right, ...) but additionally
provides Antithesis visibility into the value of left and right by merging them into the assertion's details.
public static void AlwaysGreaterThanOrEqualTo<T>(T left, T right, string message, JsonObject? details = null) where T : struct, IComparable<T>, IConvertible
Parameters
leftTThe left operand of the comparison.
rightTThe right operand of the comparison.
messagestring- A unique string identifier of the assertion. Provides context for assertion passes and failures and is intended to be human-readable. Must be provided as a string literal or as a reference to a publicly accessible const field.
detailsJsonObject- Optional additional details. Null omits details; an empty object is preserved. Serialization failures produce an antithesis_error record and the assertion still emits without details.
Type Parameters
TThe numeric type that we are comparing.
- See Also
AlwaysGreaterThan<T>(T, T, string, JsonObject?)
AlwaysGreaterThan(left, right, ...) is mostly equivalent to Always(left > right, ...) but additionally
provides Antithesis visibility into the value of left and right by merging them into the assertion's details.
public static void AlwaysGreaterThan<T>(T left, T right, string message, JsonObject? details = null) where T : struct, IComparable<T>, IConvertible
Parameters
leftTThe left operand of the comparison.
rightTThe right operand of the comparison.
messagestring- A unique string identifier of the assertion. Provides context for assertion passes and failures and is intended to be human-readable. Must be provided as a string literal or as a reference to a publicly accessible const field.
detailsJsonObject- Optional additional details. Null omits details; an empty object is preserved. Serialization failures produce an antithesis_error record and the assertion still emits without details.
Type Parameters
TThe numeric type that we are comparing.
- See Also
AlwaysLessThanOrEqualTo<T>(T, T, string, JsonObject?)
AlwaysLessThanOrEqualTo(left, right, ...) is mostly equivalent to Always(left <= right, ...) but additionally
provides Antithesis visibility into the value of left and right by merging them into the assertion's details.
public static void AlwaysLessThanOrEqualTo<T>(T left, T right, string message, JsonObject? details = null) where T : struct, IComparable<T>, IConvertible
Parameters
leftTThe left operand of the comparison.
rightTThe right operand of the comparison.
messagestring- A unique string identifier of the assertion. Provides context for assertion passes and failures and is intended to be human-readable. Must be provided as a string literal or as a reference to a publicly accessible const field.
detailsJsonObject- Optional additional details. Null omits details; an empty object is preserved. Serialization failures produce an antithesis_error record and the assertion still emits without details.
Type Parameters
TThe numeric type that we are comparing.
- See Also
AlwaysLessThan<T>(T, T, string, JsonObject?)
AlwaysLessThan(left, right, ...) is mostly equivalent to Always(left < right, ...) but additionally
provides Antithesis visibility into the value of left and right by merging them into the assertion's details.
public static void AlwaysLessThan<T>(T left, T right, string message, JsonObject? details = null) where T : struct, IComparable<T>, IConvertible
Parameters
leftTThe left operand of the comparison.
rightTThe right operand of the comparison.
messagestring- A unique string identifier of the assertion. Provides context for assertion passes and failures and is intended to be human-readable. Must be provided as a string literal or as a reference to a publicly accessible const field.
detailsJsonObject- Optional additional details. Null omits details; an empty object is preserved. Serialization failures produce an antithesis_error record and the assertion still emits without details.
Type Parameters
TThe numeric type that we are comparing.
- See Also
AlwaysOrUnreachable(bool, string, JsonObject?)
Assert that condition is true every time this method is called. The corresponding test property will pass if the assertion is never encountered.
The corresponding test property will be viewable in the Antithesis SDK: Always assertions group of your triage report.
public static void AlwaysOrUnreachable(bool condition, string message, JsonObject? details = null)
Parameters
conditionboolThe condition being asserted.
messagestringA unique string identifier of the assertion. Provides context for assertion passes and failures and is intended to be human-readable. Must be provided as a string literal or as a reference to a publicly accessible const field.
detailsJsonObjectOptional additional details. Null omits details; an empty object is preserved. Serialization failures produce an antithesis_error record and the assertion still emits without details.
AlwaysSome(IReadOnlyDictionary<string, bool>, string, JsonObject?)
AlwaysSome({ ["key1"] = bool1, ["key2"] = bool2 }, ...) is similar to Always(bool1 || bool2, ...) but additionally provides
Antithesis visibility into the keys and values of conditions by merging them into the assertion's details.
public static void AlwaysSome(IReadOnlyDictionary<string, bool> conditions, string message, JsonObject? details = null)
Parameters
conditionsIReadOnlyDictionary<string, bool>The collection of conditions to-be evaluated, represented as a Dictionary of bools keyed by strings.
messagestring- A unique string identifier of the assertion. Provides context for assertion passes and failures and is intended to be human-readable. Must be provided as a string literal or as a reference to a publicly accessible const field.
detailsJsonObject- Optional additional details. Null omits details; an empty object is preserved. Serialization failures produce an antithesis_error record and the assertion still emits without details.
- See Also
Raw(string, string, string, string, string, int, int, string, bool, string, JsonObject?, bool, bool, JsonObject?)
A low-level method designed for use by third-party frameworks that produce Antithesis-style
assertions with caller-supplied catalog metadata; regular users should call the assertion
methods above instead.
Catalog entries (hit = false) are always written without details. Hit entries are written only for
the first passing and the first failing call per id.
public static void Raw(string assertType, string displayType, string className, string functionName, string filePath, int beginLine, int beginColumn, string id, bool condition, string message, JsonObject? details, bool hit, bool mustHit, JsonObject? guidanceDetails = null)
Parameters
assertTypestringOne of
"always","sometimes", or"reachability".displayTypestringOne of
"Always","AlwaysOrUnreachable","Sometimes","Reachable", or"Unreachable".classNamestringThe name of the class containing the assertion.
functionNamestringThe name of the method containing the assertion.
filePathstringThe path of the file containing the assertion.
beginLineintThe 1-indexed line number where the assertion begins.
beginColumnintThe 1-indexed column number where the assertion begins.
idstringThe unique identifier of the assertion, used to aggregate assertions and gate emission.
conditionboolThe condition being asserted.
messagestringThe human-readable name of the corresponding test property.
detailsJsonObjectOptional additional details. Null omits details; an empty object is preserved. Serialization failures produce an antithesis_error record and the assertion still emits without details.
hitboolWhether the assertion was evaluated (
true) or is being cataloged (false).mustHitboolWhether the corresponding test property fails if the assertion is never encountered.
guidanceDetailsJsonObjectThe
{left, right}or named-bool pair a rich assertion derives from its operands, overlaid ondetailsexactly as the rich assertions overlay it — generated fields override user-supplied fields of the same name. Null for a plain assertion.
RawBooleanGuidance(bool, IReadOnlyDictionary<string, bool>, string, string, string, int, int, string, string, bool)
A low-level method designed for use by third-party frameworks that produce Antithesis-style boolean guidance with caller-supplied catalog metadata; regular users should call AlwaysSome(IReadOnlyDictionary<string, bool>, string, JsonObject?) or SometimesAll(IReadOnlyDictionary<string, bool>, string, JsonObject?) instead.
public static void RawBooleanGuidance(bool maximize, IReadOnlyDictionary<string, bool> conditions, string className, string functionName, string filePath, int beginLine, int beginColumn, string id, string message, bool hit)
Parameters
maximizeboolWhether every condition being true is the outcome being sought.
conditionsIReadOnlyDictionary<string, bool>The conditions the guidance describes, as a dictionary of bools keyed by strings.
classNamestring- The name of the class containing the assertion.
functionNamestring- The name of the method containing the assertion.
filePathstring- The path of the file containing the assertion.
beginLineint- The 1-indexed line number where the assertion begins.
beginColumnint- The 1-indexed column number where the assertion begins.
idstringThe unique identifier of the guidance.
messagestring- The human-readable name of the corresponding test property.
hitboolWhether the guidance was evaluated (
true) or is being cataloged (false).
RawNumericGuidance<T>(bool, T, T, string, string, string, int, int, string, string, bool)
A low-level method designed for use by third-party frameworks that produce Antithesis-style numeric guidance with caller-supplied catalog metadata; regular users should call the numeric guidance methods below instead.
public static void RawNumericGuidance<T>(bool maximize, T left, T right, string className, string functionName, string filePath, int beginLine, int beginColumn, string id, string message, bool hit) where T : struct, IConvertible
Parameters
maximizeboolWhether a larger
left - rightis the improvement being sought. Fixed by the first call perid.leftTThe left operand of the comparison.
rightTThe right operand of the comparison.
classNamestring- The name of the class containing the assertion.
functionNamestring- The name of the method containing the assertion.
filePathstring- The path of the file containing the assertion.
beginLineint- The 1-indexed line number where the assertion begins.
beginColumnint- The 1-indexed column number where the assertion begins.
idstringThe unique identifier of the guidance, used to key the tracked extremum.
messagestring- The human-readable name of the corresponding test property.
hitboolWhether the guidance was evaluated (
true) or is being cataloged (false).
Type Parameters
T
Reachable(string, JsonObject?)
Assert that a line of code is reached at least once. The corresponding test property will fail if the assertion is never encountered.
This test property will be viewable in the Antithesis SDK: Reachability assertions group of your triage report.
public static void Reachable(string message, JsonObject? details = null)
Parameters
messagestringA unique string identifier of the assertion. Provides context for assertion passes and failures and is intended to be human-readable. Must be provided as a string literal or as a reference to a publicly accessible const field.
detailsJsonObjectOptional additional details. Null omits details; an empty object is preserved. Serialization failures produce an antithesis_error record and the assertion still emits without details.
Sometimes(bool, string, JsonObject?)
Assert that condition is true at least one time that this method was called. The corresponding test property will fail if the assertion is never encountered.
This test property will be viewable in the Antithesis SDK: Sometimes assertions group of your triage report.
public static void Sometimes(bool condition, string message, JsonObject? details = null)
Parameters
conditionboolThe condition being asserted.
messagestringA unique string identifier of the assertion. Provides context for assertion passes and failures and is intended to be human-readable. Must be provided as a string literal or as a reference to a publicly accessible const field.
detailsJsonObjectOptional additional details. Null omits details; an empty object is preserved. Serialization failures produce an antithesis_error record and the assertion still emits without details.
SometimesAll(IReadOnlyDictionary<string, bool>, string, JsonObject?)
SometimesAll({ ["key1"] = bool1, ["key2"] = bool2 }, ...) is similar to Sometimes(bool1 && bool2, ...) but additionally provides
Antithesis visibility into the keys and values of conditions by merging them into the assertion's details.
public static void SometimesAll(IReadOnlyDictionary<string, bool> conditions, string message, JsonObject? details = null)
Parameters
conditionsIReadOnlyDictionary<string, bool>The collection of conditions to-be evaluated, represented as a Dictionary of bools keyed by strings.
messagestring- A unique string identifier of the assertion. Provides context for assertion passes and failures and is intended to be human-readable. Must be provided as a string literal or as a reference to a publicly accessible const field.
detailsJsonObject- Optional additional details. Null omits details; an empty object is preserved. Serialization failures produce an antithesis_error record and the assertion still emits without details.
- See Also
SometimesGreaterThanOrEqualTo<T>(T, T, string, JsonObject?)
SometimesGreaterThanOrEqualTo(left, right, ...) is mostly equivalent to Sometimes(left >= right, ...) but additionally
provides Antithesis visibility into the value of left and right by merging them into the assertion's details.
public static void SometimesGreaterThanOrEqualTo<T>(T left, T right, string message, JsonObject? details = null) where T : struct, IComparable<T>, IConvertible
Parameters
leftTThe left operand of the comparison.
rightTThe right operand of the comparison.
messagestring- A unique string identifier of the assertion. Provides context for assertion passes and failures and is intended to be human-readable. Must be provided as a string literal or as a reference to a publicly accessible const field.
detailsJsonObject- Optional additional details. Null omits details; an empty object is preserved. Serialization failures produce an antithesis_error record and the assertion still emits without details.
Type Parameters
TThe numeric type that we are comparing.
- See Also
SometimesGreaterThan<T>(T, T, string, JsonObject?)
SometimesGreaterThan(left, right, ...) is mostly equivalent to Sometimes(left > right, ...) but additionally
provides Antithesis visibility into the value of left and right by merging them into the assertion's details.
public static void SometimesGreaterThan<T>(T left, T right, string message, JsonObject? details = null) where T : struct, IComparable<T>, IConvertible
Parameters
leftTThe left operand of the comparison.
rightTThe right operand of the comparison.
messagestring- A unique string identifier of the assertion. Provides context for assertion passes and failures and is intended to be human-readable. Must be provided as a string literal or as a reference to a publicly accessible const field.
detailsJsonObject- Optional additional details. Null omits details; an empty object is preserved. Serialization failures produce an antithesis_error record and the assertion still emits without details.
Type Parameters
TThe numeric type that we are comparing.
- See Also
SometimesLessThanOrEqualTo<T>(T, T, string, JsonObject?)
SometimesLessThanOrEqualTo(left, right, ...) is mostly equivalent to Sometimes(left <= right, ...) but additionally
provides Antithesis visibility into the value of left and right by merging them into the assertion's details.
public static void SometimesLessThanOrEqualTo<T>(T left, T right, string message, JsonObject? details = null) where T : struct, IComparable<T>, IConvertible
Parameters
leftTThe left operand of the comparison.
rightTThe right operand of the comparison.
messagestring- A unique string identifier of the assertion. Provides context for assertion passes and failures and is intended to be human-readable. Must be provided as a string literal or as a reference to a publicly accessible const field.
detailsJsonObject- Optional additional details. Null omits details; an empty object is preserved. Serialization failures produce an antithesis_error record and the assertion still emits without details.
Type Parameters
TThe numeric type that we are comparing.
- See Also
SometimesLessThan<T>(T, T, string, JsonObject?)
SometimesLessThan(left, right, ...) is mostly equivalent to Sometimes(left < right, ...) but additionally
provides Antithesis visibility into the value of left and right by merging them into the assertion's details.
public static void SometimesLessThan<T>(T left, T right, string message, JsonObject? details = null) where T : struct, IComparable<T>, IConvertible
Parameters
leftTThe left operand of the comparison.
rightTThe right operand of the comparison.
messagestring- A unique string identifier of the assertion. Provides context for assertion passes and failures and is intended to be human-readable. Must be provided as a string literal or as a reference to a publicly accessible const field.
detailsJsonObject- Optional additional details. Null omits details; an empty object is preserved. Serialization failures produce an antithesis_error record and the assertion still emits without details.
Type Parameters
TThe numeric type that we are comparing.
- See Also
Unreachable(string, JsonObject?)
Assert that a line of code is never reached. The corresponding test property will pass if and only if the assertion is never encountered.
This test property will be viewable in the Antithesis SDK: Reachability assertions group of your triage report.
public static void Unreachable(string message, JsonObject? details = null)
Parameters
messagestringA unique string identifier of the assertion. Provides context for assertion passes and failures and is intended to be human-readable. Must be provided as a string literal or as a reference to a publicly accessible const field.
detailsJsonObjectOptional additional details. Null omits details; an empty object is preserved. Serialization failures produce an antithesis_error record and the assertion still emits without details.