Skip to content
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

excludes package and patterns is not working at all #80

Closed
periva101 opened this issue Nov 28, 2021 · 12 comments
Closed

excludes package and patterns is not working at all #80

periva101 opened this issue Nov 28, 2021 · 12 comments
Labels
S: waiting for clarification Status: additional information required to proceed

Comments

@periva101
Copy link

periva101 commented Nov 28, 2021

non of the following is working

testOptions {
        unitTests.all {
            kover {
                enabled = true
                includes = ['com\\.benoholding\\..*']
                excludes = [
                        'com\\.genoholding\\.geno\\.data\\.model\\..*',
                              
                ]
            }
        }
    }
@shanshin
Copy link
Collaborator

Hi,
could you please clarify what type of project you have (Kotlin/JVM, Kotlin Multiplatform, Android) and what Coverage Engine is used (IntelliJ, JaCoCo)?
A small reproducer or a link to the project would also help a lot.

@shanshin
Copy link
Collaborator

Relates #65

@periva101
Copy link
Author

I found that following to kover doc 'com\.genoholding\.geno\.data\.model\..', does not work
but
com.genoholding.geno.common.
is working fine

@SimonedeGijt
Copy link

SimonedeGijt commented Dec 7, 2021

Hey guys, I have troubles with excluding my testclasses from the report. First question would be; why is this even included in the first place?! Seems to be related to the fact that other test-sources like itest or contractTest are not recognised for being test code. Related to #83

@shanshin
Copy link
Collaborator

shanshin commented Dec 7, 2021

I found that following to kover doc 'com.genoholding.geno.data.model..', does not work but com.genoholding.geno.common. is working fine

Now if you use INTELLIJ as an Coverage Engine, you should write regular expressions as a filter.
e.g. com\\.genoholding\\.geno\\.data\\.model\\..*.

However, in the next release, for the filters will be used the same format as for JaCoCo, with wildcards ? and *.

@SimonedeGijt
Copy link

I found that following to kover doc 'com.genoholding.geno.data.model..', does not work but com.genoholding.geno.common. is working fine

Now if you use INTELLIJ as an Coverage Engine, you should write regular expressions as a filter. e.g. com\\.genoholding\\.geno\\.data\\.model\\..*.

However, in the next release, for the filters will be used the same format as for JaCoCo, with wildcards ? and *.

In our case the issue is not really about the regex but about the source sets it is looking at. So it's not looking inside all our source sets.

@shanshin
Copy link
Collaborator

shanshin commented Dec 7, 2021

I found that following to kover doc 'com.genoholding.geno.data.model..', does not work but com.genoholding.geno.common. is working fine

Now if you use INTELLIJ as an Coverage Engine, you should write regular expressions as a filter. e.g. com\\.genoholding\\.geno\\.data\\.model\\..*.
However, in the next release, for the filters will be used the same format as for JaCoCo, with wildcards ? and *.

In our case the issue is not really about the regex but about the source sets it is looking at. So it's not looking inside all our source sets.

These filters are not filters for the report, they determine which classes should be instrumented by the agent (estimate the coverage for them).
Filters for reports are currently in development (#17).

In this case, to exclude a class from the report, you need to exclude it from all test tasks in your project. Excluding a class in only one test task may not have an effect, since this class can be instrumented by another task and so will get into the report.

@SimonedeGijt
Copy link

Hey @shanshin, I'm not sure that I understand what you mean. I don't really know what that would look like in practise. Currently I have my configuration set like this:

withType<Test> {
        useJUnitPlatform {
            excludeTags("smoke")
        }

        extensions.configure(KoverTaskExtension::class) {
            includes = listOf("org\\.example\\..+")
            excludes = listOf(
                ".+Test",
            )
        }
    }

I made an example project to show what happens. As you can see the GreetingTest (which is part of itest) is still included in the report, whereas GreetingServiceTest (part of test) is not.

example-kover-tests.zip

@shanshin
Copy link
Collaborator

shanshin commented Dec 9, 2021

Hey @shanshin, I'm not sure that I understand what you mean. I don't really know what that would look like in practise. Currently I have my configuration set like this:

withType<Test> {
        useJUnitPlatform {
            excludeTags("smoke")
        }

        extensions.configure(KoverTaskExtension::class) {
            includes = listOf("org\\.example\\..+")
            excludes = listOf(
                ".+Test",
            )
        }
    }

I made an example project to show what happens. As you can see the GreetingTest (which is part of itest) is still included in the report, whereas GreetingServiceTest (part of test) is not.

example-kover-tests.zip

Thanks for the example!
In fact, coverage for the class GreetingTest itself is not present in the report, however, due to the fact that lambda functions are present in it, nested classes are created for them, which fall into the report.
In order to exclude them, you can write the following

        extensions.configure(KoverTaskExtension::class) {
            includes = listOf("org\\.example\\..+")
            excludes = listOf(".*Test\\$.+", ".+Test")
        }

Unfortunately, at the moment the Kover plugin does not provide to specify which source set to exclude from the instrumentation, it excludes only the source set with the name test (this feature will be added later). Therefore, I would recommend putting the test classes in a special package that can be completely excluded, for example, org.example.itest and configure

        extensions.configure(KoverTaskExtension::class) {
            excludes = listOf("org\\.example\\.itest\\..+")
        }

@shanshin
Copy link
Collaborator

@periva101, have you tested version 0.5.0-RC2?

@shanshin shanshin added the S: waiting for clarification Status: additional information required to proceed label Jan 17, 2022
@SimonedeGijt
Copy link

Hey @shanshin, do you have a reference to this feature you are talking about:
"Unfortunately, at the moment the Kover plugin does not provide to specify which source set to exclude from the instrumentation, it excludes only the source set with the name test (this feature will be added later)."

I would like to subscribe myself to it if possible :)

@shanshin
Copy link
Collaborator

Hey @shanshin, do you have a reference to this feature you are talking about:

Now there is no separate task for this, because the API design has not been finished yet.
You can look at #19, there will be added links to individual tasks for implementation: there are plans to add tasks for source sets and verification rules.

@shanshin shanshin closed this as completed Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S: waiting for clarification Status: additional information required to proceed
Projects
None yet
Development

No branches or pull requests

3 participants