Sway provides the #[test] attribute which enables unit tests to be written in Sway.
The #[test] attribute indicates that a test has passed if it did not revert.
{{#include ../../../../code/language/annotations/src/main.sw:success_test}}To test a case where code should revert we can use the #[test(should_revert)] annotation. If the test reverts then it will be reported as a passing test.
{{#include ../../../../code/language/annotations/src/main.sw:revert_test}}We may specify a code to specifically test against.
{{#include ../../../../code/language/annotations/src/main.sw:revert_code_test}}