-
Notifications
You must be signed in to change notification settings - Fork 635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "generated" annotations for Jacoco #961
Comments
Thanks for the report, we will investigate more thoroughly which signatures have to be |
Thank you! |
+1 for this. Currently relying on flaky wildcard filters on our end which don't catch everything. |
As of |
Breaks migration from jackson to serialization. Because no one will accept such degradation in code coverage measured by jacoco |
JaCoCo already filters Kotlin auto generated code by checking for the line numbers. It appears it does not work for static methods and since `kotlinx.serialization` does not apply `@Generated` annotation (another JaCoCo mechanism to skip analysis), auto generated `write\$Self` static method is included in coverage which singificantly lowers the code coverage. See Kotlin/kotlinx.serialization#961 for details
* [client] support optional input for kotlinx serialization It appears that using `@Required` annotation works on serialization and deserialization (https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/basic-serialization.md#required-properties) giving us the correct behavior for handling optional input. This PR also cleans up corresponding serialization tests to ensure we have consistent serialization between Jackson and Kotlinx Serialization. Resolves: #1151 * lower code coverage from auto generated code JaCoCo already filters Kotlin auto generated code by checking for the line numbers. It appears it does not work for static methods and since `kotlinx.serialization` does not apply `@Generated` annotation (another JaCoCo mechanism to skip analysis), auto generated `write\$Self` static method is included in coverage which singificantly lowers the code coverage. See Kotlin/kotlinx.serialization#961 for details
The issue is in the |
@mofr Indeed, it's not fixed at the moment. I'm not aware of the workarounds, but probably JaCoCo has some mechanisms to exclude certain specific names |
As a workaround - you can add the following to your Jacoco excludes:
With the wildcard packages, it may remove some other functionality from the coverage report you might want, so if you can try to target specific packages where your serialised classes are held to avoid any unnecessary fallback from this. Kotlinx plugin: 1.5.30 Hope this helps. |
@BradleyIW Your suggestion would work for whole classes based on file name, but the issue here is with generated methods like Your suggestion could have worked if the generated methods were all in a generated file, which could be excluded using file name based filter. |
…up#1250) * [client] support optional input for kotlinx serialization It appears that using `@Required` annotation works on serialization and deserialization (https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/basic-serialization.md#required-properties) giving us the correct behavior for handling optional input. This PR also cleans up corresponding serialization tests to ensure we have consistent serialization between Jackson and Kotlinx Serialization. Resolves: ExpediaGroup#1151 * lower code coverage from auto generated code JaCoCo already filters Kotlin auto generated code by checking for the line numbers. It appears it does not work for static methods and since `kotlinx.serialization` does not apply `@Generated` annotation (another JaCoCo mechanism to skip analysis), auto generated `write\$Self` static method is included in coverage which singificantly lowers the code coverage. See Kotlin/kotlinx.serialization#961 for details
|
|
I see this is closed, but is it actually fixed? I have this same problem and I'm using the following:
|
@jtaub Most of the generated declarations are marked with |
The serializer and Companion classes are still visible in my code coverage report, unless I exclude them manually, following Bradley's suggestion. |
Companion class would be visible in coverage anyway because it is visible to the user. |
I am seeing this issue as well, with kotlinx.serialization 1.6.0, Kotlin 1.9.10, and JaCoCo 0.8.10. Looking at the bytecode, while I see
(whereas for example JaCoCo also lists something labeled |
These functions are overrides from public interfaces. I'll see if it's possible to mark them synthetic. But they're used during serialization process, so they shouldn't be uncovered. |
@sandwwraith , is there are any news about it? |
@kszorin You normally would want to test the serialization to be as expected. While the generated serialization will be technically correct (probably), this does not mean that the serialization is as expected. As such tests should test serialization/deserialization, and thus trigger these code paths. |
Whether it is covered or not, whether it is good practice to test it or not, the generated code should be marked as generated. |
No, you misunderstood me. I don't want test generated code. I want the generated code to be excluded from Jacoco report. |
@kszorin I understood the "desire" to exclude it, but the code in question here is more like the result of compiling the domain specific annotations, rather than something like bridge methods. This code has developer-determined behaviour that can be incorrect. Synthetic doesn't mean generated. In some ways all code is generated. It means code created by the compiler for technical reasons that developers don't need to care about and don't provide developer-specified behaviour. My point (mainly in relation to the generated encode/decode functions) is threefold:
While |
In a real world project you will have one data class for RequestDto and one for ResponseDto. If that is the only reason that the @serializable annotations have 1 of 2 missed conditions coverage each, then this sounds fine and valid to me. I see no need to force a 100% coverage for those cases and would not test deserializing a RequestDto or serializing a ResponseDto. The important part is that there is only one missed condition reported by jacoco (for the cases mentioned above) and that there are only 2 conditions/paths to test (serialization&deserialization) when I add the annotation. It would be hard to understand that there are more than two conditions that need to be tested. |
@sarn0ld Even in a real project it makes much more sense to have a MessageDto that is shared between the sender and receiver. Even outside that it is useful that the original==deserialize(serialize(original). But I acknowledge if the service is out of your scope that you only ever read/write some data. The underlying issue for you is that the serialization generation is always symmetric, rather then having the ability to only generate one half (the interfaces for that exist in the library) - I'm not sure it is a good idea to allow that (using some additional parameter on the annotation), there are already many questions that boil down to creating serializations that don't deterministically deserialize. |
It's possible to debate these things ad infinitum, but at the end of the day, when my project with 95% test coverage drops to 60% when I refactor from Jackson to kotlinx-serialization, it becomes more difficult for me to convince my team to adopt it. |
Hi, |
What is your use-case and why do you need this feature?
kotlinx.serialization generates methods like
patch
andgetDescriptor
, which are then flagged by Jacoco as not having code coverage.Describe the solution you'd like
kotlinx.serialization generates annotations on these methods, which cause Jacoco to filter them: https://groups.google.com/g/jacoco/c/wrXjfq-NmfY/m/WXv4XuXmAAAJ
The text was updated successfully, but these errors were encountered: