Skip to content

Commit c81ede9

Browse files
m-Peterdevbugging
andauthored
Update documentation for usage of the flow test command (#165)
Co-authored-by: Gregor G <[email protected]>
1 parent 554595a commit c81ede9

File tree

1 file changed

+45
-20
lines changed

1 file changed

+45
-20
lines changed

docs/tooling/flow-cli/run-tests.md

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,30 @@ A simple Cadence script `test_script.cdc`, which has a test case for running a c
1919
```cadence
2020
import Test
2121
22-
pub fun testSimpleScript() {
23-
var blockchain = Test.newEmulatorBlockchain()
24-
var result = blockchain.executeScript(
22+
pub let blockchain = Test.newEmulatorBlockchain()
23+
24+
pub fun testSumOfTwo() {
25+
let scriptResult = blockchain.executeScript(
2526
"pub fun main(a: Int, b: Int): Int { return a + b }",
2627
[2, 3]
2728
)
28-
29-
assert(result.status == Test.ResultStatus.succeeded)
30-
assert((result.returnValue! as! Int) == 5)
29+
30+
Test.expect(scriptResult, Test.beSucceeded())
31+
32+
let sum = scriptResult.returnValue! as! Int
33+
Test.assertEqual(5, sum)
3134
}
3235
```
33-
Above test-script can be run with the CLI as follows, and the test results will be printed on the console.
36+
The above test-script can be run with the CLI as follows, and the test results will be printed on the console.
3437
```shell
35-
> flow test test_script.cdc
36-
37-
Running tests...
38+
$ flow test test_script.cdc
3839

3940
Test results: "test_script.cdc"
40-
- PASS: testSimpleScript
41+
- PASS: testSumOfTwo
4142

4243
```
4344

44-
To learn more about writing tests in Cadence, have a look at the [Cadence testing framework](../../cadence/testing-framework.mdx).
45+
To learn more about writing tests in Cadence, take a look at the [Cadence testing framework](../../cadence/testing-framework.mdx).
4546

4647
## Flags
4748

@@ -52,21 +53,45 @@ To learn more about writing tests in Cadence, have a look at the [Cadence testin
5253

5354
Use the `cover` flag to calculate coverage report for the code being tested.
5455
```shell
55-
> flow test --cover test_script.cdc
56-
57-
Running tests...
56+
$ flow test --cover test_script.cdc
5857

5958
Test results: "test_script.cdc"
60-
- PASS: testSimpleScript
61-
Coverage: 100.0% of statements
59+
- PASS: testSumOfTwo
60+
Coverage: 96.5% of statements
6261

6362
```
6463

6564
### Coverage Report File
6665

6766
- Flag: `--coverprofile`
68-
- Valid inputs: valid filename
69-
- Default: `coverage.json`
67+
- Valid inputs: valid filename and extension
68+
- Default: `"coverage.json"`
69+
70+
Use the `coverprofile` to specify the filename where the calculated coverage report is to be written. Supported filename extensions are `.json` and `.lcov`.
71+
```shell
72+
$ flow test --cover test_script.cdc
73+
74+
$ cat coverage.json
75+
76+
$ flow test --cover --coverprofile="coverage.lcov" test_script.cdc
77+
78+
$ cat coverage.lcov
79+
```
80+
81+
### Coverage Code Type
82+
83+
- Flag: `--covercode`
84+
- Valid inputs: `"all"`, `"contracts"`
85+
- Default: `"all"`
86+
87+
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.
88+
```shell
89+
$ flow test --cover --covercode="contracts" test_script.cdc
90+
91+
Test results: "tests/test_script.cdc"
92+
- PASS: testSumOfTwo
93+
There are no statements to cover
94+
```
7095

71-
Use the `coverprofile` to specify the filename where the calculated coverage report is to be written.
96+
Since we did not use any contracts in our sample test script, there is no coverage percentage to be reported.
7297

0 commit comments

Comments
 (0)