Overview
The Antithesis Rust SDK crate provides modules for placing your Rust code under test and using Antithesis functionality. It is available on Github and on crates.io.Modules
The Rust SDK is distributed as a crate containing several modules. Each of the three modules provides a separate type of functionality:- The rust assert macros define test properties about your software or workload.
- The random functions request both structured and unstructured randomness from the Antithesis platform.
- The lifecycle functions inform the Antithesis environment that particular test phases or milestones have been reached.
Using the Rust SDK
The basic workflow for using the Rust SDK is:- Include it as a dependency in Cargo.toml. Check crates for the specific version.
-
Call
antithesis_init()at the beginning of your program. -
Call other SDK functions from your code. For example create a test property with an assertion
such as
assert_always!(bool_expression, ...other_args); - Build your code:
If you intend to deploy this build to Antithesis, ensure you build with instrumentation.
- Deploy your build: either to Antithesis or into production.
SDK runtime behavior
When your code is run outside Antithesis, our SDK has sensible fallback behavior with minimal performance overhead. This enables you to have a single build of your software that runs both inside and outside Antithesis. One benefit of this is that Sometimes Assertions continue to function outside Antithesis, and can be quite useful for discovering what states of your program are encountered during real-world use. The assert macros and lifecycle functions have three possible modes for local execution:-
Default, where
assertandlifecycleuse local implementations of Antithesis functionality. However, the results will not be logged anywhere because no logfile has been specified. This mode is enabled by thefullfeature flag. The flag is enabled by default. -
Default with logging, which is the same as the above but logs output locally in a structured JSON format.
This mode is selected at runtime by setting the environment variable
ANTITHESIS_SDK_LOCAL_OUTPUTat program startup. This variable must be set to a filepath: a logfile will be created at this location. The file must be located inside an already-existing directory. You may supply either a relative or absolute path. For example, you could setANTITHESIS_SDK_LOCAL_OUTPUT=assertions_20240520.jsonat startup to implement this mode. -
No-op, which disables
lifecycleandassertcalls and skips over them at low cost. In particular, the arguments to these functions are evaluated, but the functions are stubbed-out. This mode is selected at build-time by disabling all default features for the sdk crate. For example, yourCargo.tomlmight look like the following: