assert
To make sure our tests work, we use assert.
fn main(x: felt252, y: felt252) {
assert(x != y, 'error, x is equal to y');
}
#[test]
fn test_main() {
main(1,2);
}
The first argument of assert is the condition we want to check, and the second is a message we will see on the console if the condition is false.
Run cairo-test file_name
Try changing it so that the test fails.
Try it out!
- Install the toolchain:
- For macOS and Linux, run our script:
curl -sL https://raw.githubusercontent.com/lambdaclass/cairo-by-example/main/build/installer.sh | bash -s 2.2.0
- For Windows and others, please see the official guide
- Run the example:
- Copy the example into a assert.cairo file and run with:
%!s(<nil>) assert.cairo