Kover JVM instrumentation agent
On the fly instrumentation
On the fly instrumentation - modification of the bytecode of classes in order to measure coverage, that occurs when the class is loaded into the JVM.
To instrument the loaded classes, it is necessary to connect a JVM agent to the Java application being launched.
Getting a readable report
To get a readable coverage report, you need to:
- Connect JVM agent on JVM start.
- Run your tests and wait until it exits. When the application is finished, the binary report file will be saved.
- Using the Kover CLI, generate a human-readable report from a binary report.
Connecting the JVM agent
- Download the latest version of the Kover JVM agent jar from maven repository.
- Put JVM agent jar file in a local directory (Important! renaming a jar file is not allowed).
- Create a file with agent arguments, learn more about the arguments.
- Add an argument to the java application startup command
-javaagent:<path_to_agent_jar>=file:<path_to_settings_file>
. Example of an application launch commandjava -javaagent:/opt/kover-jvm-agent-0.8.3.jar=file:/tmp/agent.args -jar application.jar
.
Kover JVM arguments file
The arguments file is a set of settings, each of which is written on a new line.
Line format: argument_name=argument_value
report.file
argument is required, while the rest are optional.
List of all available arguments:
report.file
- path to the file, which will contain a binary coverage report in ic format. The file is created if it did not exist beforereport.append
- it is acceptable to specify true or false. if true, then if the file will be appended if the coverage is already stored in it-
exclude
- specify which classes do not need to be modified when loading. For such classes, the coverage will always be 0.It is acceptable to use
*
and?
wildcards,*
means any number of arbitrary characters (including no chars),?
means one arbitrary character. -
exclude.regex
- specify which classes do not need to be modified when loading. For such classes, the coverage will always be 0.It is acceptable to specify regex.
-
include
- specify which classes will be modified when loading, all other classes will not.It is acceptable to use
*
and?
wildcards,*
means any number of arbitrary characters (including no chars),?
means one arbitrary character. -
include.regex
- specify which classes will be modified when loading, all other classes will not.It is acceptable to specify regex.
It is possible to use exclude
and exclude.regex
at the same time, also include
and include.regex
.
Example of arguments file:
report.file=/tmp/kover-report.ic
exclude=com.example.*