You can use the maxHeapSize configuration of the Test task.
Example in Gradle/Groovy:
test {
minHeapSize = "128m" // initial heap size
maxHeapSize = "512m" // maximum heap size
jvmArgs '-XX:MaxPermSize=256m' // mem argument for the test JVM
}
Or the same in Kotlin:
withType<Test> {
minHeapSize = "512m"
maxHeapSize = "1024m"
jvmArgs = listOf("-XX:MaxPermSize=512m")
}
Check out the official docs for additional info.