22

Gradle has the test configuration block

https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html

```

apply plugin: 'java' // adds 'test' task

test {
  // enable TestNG support (default is JUnit)
  useTestNG()

  // set a system property for the test JVM(s)
  systemProperty 'some.prop', 'value'

  // explicitly include or exclude tests
  include 'org/foo/**'
  exclude 'org/boo/**'

  // show standard out and standard error of the test JVM(s) on the console
  testLogging.showStandardStreams = true

  // set heap size for the test JVM(s)
  minHeapSize = "128m"
  maxHeapSize = "512m"

  // set JVM arguments for the test JVM(s)
  jvmArgs '-XX:MaxPermSize=256m'

  // listen to events in the test execution lifecycle
  beforeTest { descriptor ->
     logger.lifecycle("Running test: " + descriptor)
  }

  // listen to standard out and standard error of the test JVM(s)
  onOutput { descriptor, event ->
     logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
  }
}

where one can set all sorts of test configuration (I am mostly interested in the heap size). Is there something similar for android projects?

sakis kaliakoudas
  • 2,039
  • 4
  • 31
  • 51

1 Answers1

21

There is a possibility to add them. Android Gradle plugin has parameter testOptions, which has parameter unitTests, which has option all.

So if you write:

android {
    testOptions {
        unitTests.all {
           // apply test parameters
        }
    }
}

the tests will be executed with specified parameters.

Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
R. Zagórski
  • 20,020
  • 5
  • 65
  • 90
  • that's what I was looking for thanks. I was even already using it but I totally missed it when I started getting out of memory errors when running my tests. I tried a couple more of the parameters found here https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html and they seemed to work – sakis kaliakoudas Oct 16 '16 at 21:52