Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set unit test jvmargs using gradle kotlin dsl

I'm trying to set jvmargs for unit tests using kotlin-dsl and I can't get it to work.

This is so that I can add the "-noverify" argument and allow intellji test runner to collect code coverage info.

Groovy, works:

testOptions {
        unitTests.all {
            jvmArgs '-noverify'
        }
    }

Kotlin, doesn't work:

testOptions {
        unitTests.all(KotlinClosure1<Any, Test>({
            (this as Test).also { jvmArgs("-noverify") }
        }, this))
    }

This too:

testOptions {
        unitTests.all(KotlinClosure1<Any, Test>({
            (this as Test).also { jvmArgs = listOf("-noverify") }
        }, this))
    }

Nothing seems to work, what am I missing?

like image 761
Mahmoud AlyuDeen Avatar asked Sep 18 '19 21:09

Mahmoud AlyuDeen


Video Answer


1 Answers

I was having the same issue. The following snippet works.

tasks.withType<Test>().all {
    jvmArgs("-noverify")
}

Ref - https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html#jvmArgs-java.lang.Object...-

Verified using Gradle-5.1.-all version

like image 71
omni.present Avatar answered Sep 28 '22 15:09

omni.present