Testing Framework Overview
Sui supports two main testing approaches:- Unit tests: Test individual functions in isolation
- Scenario tests: Test multi-transaction flows simulating real usage
Writing Unit Tests
Unit tests use the#[test] attribute and run in a simulated environment.
Basic Test Structure
Test-Only Code
Use#[test_only] for code that only exists in tests:
Expected Failures
Test that code fails correctly:Scenario Testing
Scenario tests simulate multi-transaction flows usingtest_scenario.
Example from First Package
Based on the actual Sui codebasefirst_package example:
Testing Module Initialization
From thefirst_package example:
Testing Shared Objects
Test shared objects usingtake_shared and return_shared:
Real-World Example: Flash Loan Tests
Fromexamples/move/flash_lender: