Grails 4 Code Coverage

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Grails 4 Code Coverage

Jessie Evangelista
Hi all,

We are considering using grails 4.0.0 for a new product and we'd like to do it the right way from the start. 

It seems there are no plugins yet for code coverage in the grails3 list:
 
The plugins for grails 1 and 2 also dont work:
OpenClover Code Coverage for Grails
Test Code Coverage Plugins

What is the best way to implement code coverage measurement for a grails4 web application?


--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/641e8191-7f1e-4254-b572-b660a18d1f76%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Grails 4 Code Coverage

Jeff Scott Brown-4
On 30 Aug 2019, at 2:00, Jessie Evangelista wrote:

> Hi all,
>
> We are considering using grails 4.0.0 for a new product and we'd like to do
> it the right way from the start.
>
> It seems there are no plugins yet for code coverage in the grails3 list:
> http://plugins.grails.org/?query=coverage&submit=Search
>
> The plugins for grails 1 and 2 also dont work:
> OpenClover Code Coverage for Grails
> Test Code Coverage Plugins
>
> What is the best way to implement code coverage measurement for a grails4
> web application?
>

JaCoCo is quite popular.

https://docs.gradle.org/current/userguide/jacoco_plugin.html



JSB
--
Jeff Scott Brown
Partner and Practice Lead, Grails and Micronaut

Disruptive solutions for a connected world.™
http://objectcomputing.com

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/6FA75708-1D28-474F-AB63-8A5B8B25D877%40objectcomputing.com.
Reply | Threaded
Open this post in threaded view
|

Re: Grails 4 Code Coverage

Jeff Scott Brown-4
On 30 Aug 2019, at 10:07, Jeff Scott Brown wrote:

> On 30 Aug 2019, at 2:00, Jessie Evangelista wrote:
>
>> Hi all,
>>
>> We are considering using grails 4.0.0 for a new product and we'd like
>> to do
>> it the right way from the start.
>>
>> It seems there are no plugins yet for code coverage in the grails3
>> list:
>> http://plugins.grails.org/?query=coverage&submit=Search
>>
>> The plugins for grails 1 and 2 also dont work:
>> OpenClover Code Coverage for Grails
>> Test Code Coverage Plugins
>>
>> What is the best way to implement code coverage measurement for a
>> grails4
>> web application?
>>
>
> JaCoCo is quite popular.
>
> https://docs.gradle.org/current/userguide/jacoco_plugin.html
>
>
>

FYI… I had not used it with Grails 4 yet but just created a simple app
to see if it appears to work and it does.

I just created a new app and added the following to build.gradle:

plugins {
     id 'jacoco'
}


jacocoTestReport {
     executionData test, integrationTest
}


That seems to generate the expected reports.





JSB

--
Jeff Scott Brown
Partner and Practice Lead, Grails and Micronaut

Disruptive solutions for a connected world.™
http://objectcomputing.com

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/4BAFC31D-9D67-4E45-9DAA-EEDB2BF61556%40objectcomputing.com.
Reply | Threaded
Open this post in threaded view
|

Re: Grails 4 Code Coverage

Jessie Evangelista
Thank you for this. here is what I did with it:
grails create-app foo-app && cd foo-app
cat >> build.gradle << 'EOF'
apply plugin:"jacoco"
jacoco {
    toolVersion = "0.8.4"
}
jacocoTestReport {
    dependsOn test
    reports {
        xml.enabled false
        csv.enabled false
        html.destination file("${buildDir}/reports/jacocoHtml")
    }
}
EOF

mkdir -p grails-app/domain/foo/app/
cat >> grails-app/domain/foo/app/Bar.groovy << EOF
package foo.app

class Bar {
    String name

    static constraints = {
    }
}
EOF
mkdir -p src/test/groovy/foo/app/
cat >> src/test/groovy/foo/app/BarSpec.groovy << EOF
package foo.app

import grails.testing.gorm.DomainUnitTest
import spock.lang.Specification

class BarSpec extends Specification implements DomainUnitTest<Bar> {

    def setup() {
    }

    def cleanup() {
    }

    void "test should have name property"() {
        Bar bar = new Bar()
        bar.name = "valid"
        expect:"name should be retained"
        "valid".equals(bar.name)
    }
}
EOF
grails gradle jacocoTestReport
firefox build/reports/jacocoHtml/index.html

Which got me the image below:

Screenshot at 2019-08-30 18-23-44.png


As can be seen, jacoco includes the injected methods in coverage computation.
Is there a quick way to exclude the generated methods?


 

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/21ee2ea2-2307-48c8-b1a3-d36f386bcbd2%40googlegroups.com.