You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
34
37
```shell
35
-
> flow test test_script.cdc
36
-
37
-
Running tests...
38
+
$ flow test test_script.cdc
38
39
39
40
Test results: "test_script.cdc"
40
-
- PASS: testSimpleScript
41
+
- PASS: testSumOfTwo
41
42
42
43
```
43
44
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).
45
46
46
47
## Flags
47
48
@@ -52,21 +53,45 @@ To learn more about writing tests in Cadence, have a look at the [Cadence testin
52
53
53
54
Use the `cover` flag to calculate coverage report for the code being tested.
54
55
```shell
55
-
> flow test --cover test_script.cdc
56
-
57
-
Running tests...
56
+
$ flow test --cover test_script.cdc
58
57
59
58
Test results: "test_script.cdc"
60
-
- PASS: testSimpleScript
61
-
Coverage: 100.0% of statements
59
+
- PASS: testSumOfTwo
60
+
Coverage: 96.5% of statements
62
61
63
62
```
64
63
65
64
### Coverage Report File
66
65
67
66
- 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
+
```
70
95
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.
0 commit comments