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
Introduced Offline Runtime API for saving binary report
- implemented API method to get binary report as a byte array
- implemented API method to save binary report
- bump Intellij Coverage Library to `1.0.740`
Co-authored-by: Leonid Startsev <sandwwraith@users.noreply.github.com>
Resolves#503
PR #500
Copy file name to clipboardexpand all lines: docs/offline-instrumentation/index.md
+50-8
Original file line number
Diff line number
Diff line change
@@ -18,27 +18,56 @@ must be passed to Kover CLI as arguments, see [Kover CLI](../cli#offline-instrum
18
18
19
19
To run classes instrumented offline, you'll need to add `org.jetbrains.kotlinx:kover-offline` artifact to the application's classpath.
20
20
21
-
There are two ways to get coverage:
21
+
There are several ways to get coverage:
22
22
23
-
- Run tests to get a binary report file, then run [Kover CLI](../cli#generating-reports) to get HTML or XML report from binary report
24
-
- Call `KoverRuntime.collectByDirs` or `KoverRuntime.collect` in the same process after the tests are finished
23
+
-[Save binary report file when the JVM is shut down](#save-binary-report-on-shut-down)
24
+
-[Save binary report in runtime by Kover API](#save-binary-report-in-runtime)
25
+
-[Get binary report in runtime by Kover API](#get-binary-report-in-runtime)
26
+
-[Get coverage details in runtime by Kover API](#get-coverage-details-in-runtime)
25
27
26
-
One or both of these ways can be used at the same time.
28
+
Binary reports are presented in `ic` format, and can later be used in the [Kover CLI](../cli#generating-reports) to generate HTML or XML reports.
27
29
28
-
#### Binary report file
30
+
#### Save binary report on shut down
29
31
30
-
You'll also need to pass the system property `kover.offline.report.path` to the application with the path where you want a binary report to be saved.
31
-
This binary file can be used to generate human-readable reports using [Kover CLI](../cli#generating-reports).
32
+
You'll need to pass the system property `kover.offline.report.path` to the application with the path where you want a binary report to be saved.
32
33
33
-
#### In-process reporting
34
+
If this property is specified, then at the end of the JVM process,
35
+
the binary coverage report will be saved to a file at the path passed in the parameter value.
36
+
37
+
If the file does not exist, it will be created. If a file with that name already exists, it will be overwritten.
38
+
39
+
#### Save binary report in runtime
40
+
41
+
Inside the same JVM process in which the tests were run, call Java static method `kotlinx.kover.offline.runtime.api.KoverRuntime.saveReport`.
42
+
43
+
If the file does not exist, it will be created. If a file already exists, it will be overwritten.
44
+
45
+
Calling this method is allowed only after all tests are completed. If the method is called in parallel with the execution of the measured code, the coverage value is unpredictable.
46
+
47
+
#### Get binary report in runtime
48
+
49
+
Inside the same JVM process in which the tests were run, call Java static method `kotlinx.kover.offline.runtime.api.KoverRuntime.getReport`.
50
+
This method will return byte array with a binary coverage report, which can be saved to a file later.
51
+
It is important that this byte array cannot be appended to an already existing file, and must be saved to a separate file.
52
+
53
+
Calling this method is allowed only after all tests are completed. If the method is called in parallel with the execution of the measured code, the coverage value is unpredictable.
54
+
55
+
#### Get coverage details in runtime
34
56
35
57
Inside the same JVM process in which the tests were run, call Java static method `kotlinx.kover.offline.runtime.api.KoverRuntime.collectByDirs` or `kotlinx.kover.offline.runtime.api.KoverRuntime.collect`.
36
58
37
59
For correct generation of the report, it is necessary to pass the bytecode of the non-instrumented classes.
38
60
This can be done by specifying the directories where the class-files are stored, or a byte array with the bytecode of the application non-instrumented classes.
39
61
62
+
Calling these methods is allowed only after all tests are completed. If the method is called in parallel with the execution of the measured code, the coverage value is unpredictable.
63
+
40
64
See [example](#example-of-using-the-api).
41
65
66
+
## Logging
67
+
`org.jetbrains.kotlinx:kover-offline` has its own logging system.
68
+
69
+
By default, error messages are saved to a file in the working directory with the name `kover-offline.log`. To change the path to this file, pass the `kover.offline.log.file.path` system property with new path.
* Save coverage binary report in file with ic format.
72
+
* If the file does not exist, it will be created. If a file already exists, it will be overwritten.
73
+
* <p/>
74
+
* Calling this method is allowed only after all tests are completed. If the method is called in parallel with the execution of the measured code, the coverage value is unpredictable.
75
+
*
76
+
*
77
+
* @param file the file to save binary report
78
+
* @throws IOException in case of any error working with files
* Get content of the coverage binary report with ic format.
93
+
* The resulting byte array can be directly saved to an ic file for working with the CLI
94
+
* <p/>
95
+
* Calling this method is allowed only after all tests are completed. If the method is called in parallel with the execution of the measured code, the coverage value is unpredictable.
96
+
*
97
+
*
98
+
* @return byte array with binary report in ic format
99
+
* @throws IOException in case of any error working with files
0 commit comments