How to Write Unit Tests
The following is an example of a unit test, written to test the increment contract. The contract has anincrement function, that increases a counter value by one on every invocation. The following test invokes that contract’s function several times, and checks that the value increases by one.
-
Create an environment, the
Env. -
Register the contract(s) to be tested. Include as a second parameter any constructor parameters.
-
Invoke functions using the generated client.
-
Assert the outcome.
The
Env created at the beginning of the test is not a simulation of the Soroban Environment. It’s the same Soroban Environment that mainnet uses to execute contracts. There are only some minor differences: test utilities are enabled, and the storage backend is different.- Create an environment, the
Env. - Register the contract(s) to be tested.
- Invoke functions using a client.
- Assert the outcome.