@@ -43,6 +43,7 @@ open class AndroidJUnitPlatformExtension(private val project: Project) {
4343 * The version of JUnit Platform to use
4444 */
4545 var platformVersion: String? = null
46+
4647 fun platformVersion (version : String? ) {
4748 this .platformVersion = version
4849 }
@@ -51,6 +52,7 @@ open class AndroidJUnitPlatformExtension(private val project: Project) {
5152 * The version of JUnit Jupiter to use
5253 */
5354 var jupiterVersion: String? = null
55+
5456 fun jupiterVersion (version : String? ) {
5557 this .jupiterVersion = version
5658 }
@@ -59,6 +61,7 @@ open class AndroidJUnitPlatformExtension(private val project: Project) {
5961 * The version of JUnit Vintage to use
6062 */
6163 var vintageVersion: String? = null
64+
6265 fun vintageVersion (version : String? ) {
6366 this .vintageVersion = version
6467 }
@@ -67,6 +70,7 @@ open class AndroidJUnitPlatformExtension(private val project: Project) {
6770 * The directory for the test report files
6871 */
6972 var reportsDir: File ? = null
73+
7074 fun reportsDir (reportsDir : File ? ) {
7175 // Work around for https://discuss.gradle.org/t/bug-in-project-file-on-windows/19917
7276 if (reportsDir is File ) {
@@ -82,6 +86,7 @@ open class AndroidJUnitPlatformExtension(private val project: Project) {
8286 * system property to this value
8387 */
8488 var logManager: String? = null
89+
8590 fun logManager (logManager : String? ) {
8691 this .logManager = logManager
8792 }
@@ -90,6 +95,7 @@ open class AndroidJUnitPlatformExtension(private val project: Project) {
9095 * Whether or not the standard Gradle {@code test} task should be enabled
9196 */
9297 var enableStandardTestTask = false
98+
9399 fun enableStandardTestTask (state : Boolean ) {
94100 this .enableStandardTestTask = state
95101 }
@@ -98,6 +104,7 @@ open class AndroidJUnitPlatformExtension(private val project: Project) {
98104 * Select test execution plan details mode
99105 */
100106 var details = Details .NONE
107+
101108 fun details (details : Details ) {
102109 this .details = details
103110 }
@@ -157,7 +164,7 @@ open class AndroidJUnitPlatformExtension(private val project: Project) {
157164 *
158165 * @since 1.0.23
159166 */
160- val unitTests = UnitTestOptions ()
167+ val unitTests = UnitTestOptions (project )
161168
162169 /* *
163170 * Configures unit test options
@@ -462,7 +469,7 @@ open class IncludeExcludeContainer {
462469/* *
463470 * Options for controlling how JUnit 5 Unit Tests should be executed
464471 */
465- class UnitTestOptions {
472+ class UnitTestOptions ( private val project : Project ) {
466473
467474 operator fun invoke (config : UnitTestOptions .() -> Unit ) {
468475 this .config()
@@ -482,10 +489,58 @@ class UnitTestOptions {
482489 * - environment variables
483490 */
484491 var applyDefaultTestOptions = true
492+
485493 fun applyDefaultTestOptions (state : Boolean ) {
486494 this .applyDefaultTestOptions = state
487495 }
488496
497+ /* *
498+ * Whether unmocked methods from android.jar should throw exceptions or return default
499+ * values (i.e. zero or null).
500+ *
501+ * Defaults to false, which will throw exceptions on unmocked method invocations
502+ *
503+ * @since 1.0.32
504+ */
505+ var returnDefaultValues: Boolean
506+ get() = project.android.testOptions.unitTests.isReturnDefaultValues
507+ set(value) {
508+ project.android.testOptions.unitTests.isReturnDefaultValues = value
509+ }
510+
511+ /* *
512+ * Enables unit tests to use Android resources, assets, and manifests.
513+ * <p>
514+ * If you enable this setting, the Android Gradle Plugin performs resource, asset,
515+ * and manifest merging before running your unit tests. Your tests can then inspect a file
516+ * called {@code com/android/tools/test_config.properties} on the classpath, which is a Java
517+ * properties file with the following keys:
518+ *
519+ * <ul>
520+ * <li><code>android_sdk_home</code>: the absolute path to the Android SDK.
521+ * <li><code>android_merged_resources</code>: the absolute path to the merged resources
522+ * directory, which contains all the resources from this subproject and all its
523+ * dependencies.
524+ * <li><code>android_merged_assets</code>: the absolute path to the merged assets
525+ * directory. For app subprojects, the merged assets directory contains assets from
526+ * this subproject and its dependencies. For library subprojects, the merged assets
527+ * directory contains only the assets from this subproject.
528+ * <li><code>android_merged_manifest</code>: the absolute path to the merged manifest
529+ * file. Only app subprojects merge manifests of its dependencies. So, library
530+ * subprojects won't include manifest components from their dependencies.
531+ * <li><code>android_custom_package</code>: the package name of the final R class. If you
532+ * modify the application ID in your build scripts, this package name may not match
533+ * the <code>package</code> attribute in the final app manifest.
534+ * </ul>
535+ *
536+ * @since 1.0.32
537+ */
538+ var includeAndroidResources: Boolean
539+ get() = project.android.testOptions.unitTests.isIncludeAndroidResources
540+ set(value) {
541+ project.android.testOptions.unitTests.isIncludeAndroidResources = value
542+ }
543+
489544 /* *
490545 * Applies the provided config closure to all JUnit 5 test tasks,
491546 * and any task that'll be added in the future
@@ -535,6 +590,7 @@ class InstrumentationTestOptions {
535590 * Whether or not to enable support for JUnit 5 instrumentation tests
536591 */
537592 var enabled: Boolean = true
593+
538594 fun enabled (state : Boolean ) {
539595 this .enabled = state
540596 }
@@ -543,6 +599,7 @@ class InstrumentationTestOptions {
543599 * The version of the instrumentation companion library to use
544600 */
545601 var version: String? = null
602+
546603 fun version (version : String? ) {
547604 this .version = version
548605 }
@@ -562,6 +619,7 @@ class JacocoOptions {
562619 * Whether or not to enable Jacoco task integration
563620 */
564621 var taskGenerationEnabled = true
622+
565623 fun taskGenerationEnabled (state : Boolean ) {
566624 this .taskGenerationEnabled = state
567625 }
@@ -620,13 +678,15 @@ class JacocoOptions {
620678 * By default, this will exclude R.class & BuildConfig.class
621679 */
622680 var excludedClasses = mutableListOf (" **/R.class" , " **/R$*.class" , " **/BuildConfig.*" )
681+
623682 fun excludedClasses (vararg classes : String ) = excludedClasses.addAll(classes)
624683
625684 /* *
626685 * List of source name patterns that should be excluded from being processed by Jacoco.
627686 * By default, this is an empty list
628687 */
629688 var excludedSources = mutableListOf<String >()
689+
630690 fun excludedSources (vararg sources : String ) = excludedSources.addAll(sources)
631691
632692 class Report {
@@ -639,6 +699,7 @@ class JacocoOptions {
639699 * Whether or not this report should be generated
640700 */
641701 var enabled: Boolean = true
702+
642703 fun enabled (state : Boolean ) {
643704 this .enabled = state
644705 }
@@ -649,6 +710,7 @@ class JacocoOptions {
649710 * each variant will be assigned a distinct folder if necessary
650711 */
651712 var destination: File ? = null
713+
652714 fun destination (file : File ? ) {
653715 this .destination = file
654716 }
0 commit comments