Run Cadence tests
The Flow CLI provides a command to run Cadence tests.
⚠️ The test
command expects configuration to be initialized. See flow init command.
Example Usage
A simple Cadence script test_script.cdc
, which has a test case for running a cadence script on-chain:
The above test-script can be run with the CLI as follows, and the test results will be printed on the console.
To learn more about writing tests in Cadence, take a look at the Cadence testing framework.
Flags
Coverage
- Flag:
--cover
- Default:
false
Use the cover
flag to calculate coverage report for the code being tested.
Coverage Report File
- Flag:
--coverprofile
- Valid inputs: valid filename and extension
- Default:
"coverage.json"
Use the coverprofile
to specify the filename where the calculated coverage report is to be written. Supported filename extensions are .json
and .lcov
.
Coverage Code Type
- Flag:
--covercode
- Valid inputs:
"all"
,"contracts"
- Default:
"all"
Use the covercode
flag to calculate coverage report only for certain types of code. A value of "contracts"
will exclude scripts and transactions from the coverage report.
Since we did not use any contracts in our sample test script, there is no coverage percentage to be reported.