Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle - equivalent of test {} configuration block for android

Tags:

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?

like image 675
sakis kaliakoudas Avatar asked Sep 11 '16 15:09

sakis kaliakoudas


People also ask

How do I create a test folder in Android?

To add a testing source set for your build variant in Android Studio, follow these steps: In the Project window on the left, click the drop-down menu and select the Project view. Within the appropriate module folder, right-click the src folder and click New > Directory.

What is BuildConfig in Android?

What is BuildConfig? Gradle generates a BuildConfig class that contains static configuration constants that are specific to the build at build time. The class includes default fields such as debug and flavor, but you can override them with build.

What is Buildtype in gradle Android?

A build type determines how an app is packaged. By default, the Android plug-in for Gradle supports two different types of builds: debug and release . Both can be configured inside the buildTypes block inside of the module build file.

What is Android plugin for gradle?

The Android Gradle plugin (AGP) is the official build system for Android applications. It includes support for compiling many different types of sources and linking them together into an application that you can run on a physical Android device or an emulator.


1 Answers

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.

like image 198
R. Zagórski Avatar answered Sep 21 '22 06:09

R. Zagórski