简体   繁体   中英

Run Unit tests with gradlew and custom JRE

I am trying to run my project's unit tests using the Gradle wrapper in order to integrate the development with Jenkins. The problem is that I have to run the tests using the JRE option in the GUI to Android-28 but the project is compiled with Android-26 due to some limitations.

How can I select the JRE using the Gradle wrapper? Is there something like:

./gradlew test --api 28

You can create a build variant for testing.

eg in you app level gradle file, add a product flavour say jenkins ,

buildTypes {
  release {...}
  debug {...}
}

flavorDimensions "version"
productFlavors {
   jenkins {
      dimension "version"
      minSdkVersion 28 
      ... 
   }
}

Then call:

./gradlew testJenkinsDebugUnitTest

For more info refer Test from the command line

Two ways

  1. In gradle.properties in the .gradle directory in your HOME_DIRECTORY set org.gradle.java.home=/path_to_jdk_directory

or:

  1. In your build.gradle

     compileJava.options.fork = true compileJava.options.forkOptions.executable = /path_to_javac

and if you don't want to depend on concrete path then maybe third approach.

3.) If you add JDK_PATH in **gradle.properties** your build become dependent on on that particular path. Instead Run **gradle task** with following command line parametemer

gradle build -Dorg.gradle.java.home=/JDK_PATH

This way your build is not dependent on some concrete path.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM