From 45d7e7f557fa861b5d9fa761e5d6940c33c9738a Mon Sep 17 00:00:00 2001 From: Adam Kobus Date: Mon, 26 Sep 2016 13:13:15 +0200 Subject: [PATCH] ST-176 Added ignoreFailures option to tests --- README.md | 7 +++- .../toolkit/ToolkitConfiguration.groovy | 2 + .../impl/android/VariantConfigurator.groovy | 2 + .../variant/ConfigureTestsForVariant.groovy | 37 +++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/main/groovy/com/infullmobile/toolkit/impl/android/commands/variant/ConfigureTestsForVariant.groovy diff --git a/README.md b/README.md index 4d14010..d315181 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ buildscript { } } dependencies { - classpath 'com.infullmobile:toolkit:0.3.14' + classpath 'com.infullmobile:toolkit:0.3.18' } } ``` @@ -206,6 +206,11 @@ Default: `true` If set to true, then custom check tasks will also run tests and test results will be copied to `results/test` directory. +#### ignoreTestErrors +Default: `false` + +If set to true, then verification tasks won't fail due to failed tests. + #### configureCheckstyle Default: `true` diff --git a/src/main/groovy/com/infullmobile/toolkit/ToolkitConfiguration.groovy b/src/main/groovy/com/infullmobile/toolkit/ToolkitConfiguration.groovy index a702e06..2e31d23 100644 --- a/src/main/groovy/com/infullmobile/toolkit/ToolkitConfiguration.groovy +++ b/src/main/groovy/com/infullmobile/toolkit/ToolkitConfiguration.groovy @@ -22,7 +22,9 @@ class ToolkitConfiguration { def boolean configureCoverage = false def boolean useJava8 = false; def boolean appendVersionNameToAPK = false; + def boolean configureTests = true; + def boolean ignoreTestErrors = false; def boolean configureCheckstyle = true; def boolean ignoreCheckstyleFailures = true; diff --git a/src/main/groovy/com/infullmobile/toolkit/impl/android/VariantConfigurator.groovy b/src/main/groovy/com/infullmobile/toolkit/impl/android/VariantConfigurator.groovy index 571c8e2..2f147d3 100644 --- a/src/main/groovy/com/infullmobile/toolkit/impl/android/VariantConfigurator.groovy +++ b/src/main/groovy/com/infullmobile/toolkit/impl/android/VariantConfigurator.groovy @@ -3,6 +3,7 @@ package com.infullmobile.toolkit.impl.android import com.infullmobile.toolkit.impl.android.commands.variant.ConfigureCheckstyleForVariant import com.infullmobile.toolkit.impl.android.commands.variant.ConfigureFindbugsInVariant import com.infullmobile.toolkit.impl.android.commands.variant.ConfigureLintForVariant +import com.infullmobile.toolkit.impl.android.commands.variant.ConfigureTestsForVariant import com.infullmobile.toolkit.impl.android.commands.variant.CopyTestResultsCommand import com.infullmobile.toolkit.types.IProjectConfigurator @@ -22,6 +23,7 @@ class VariantConfigurator extends IProjectConfigurator { new ConfigureCheckstyleForVariant(), new ConfigureFindbugsInVariant(), new CopyTestResultsCommand(), + new ConfigureTestsForVariant() ) } diff --git a/src/main/groovy/com/infullmobile/toolkit/impl/android/commands/variant/ConfigureTestsForVariant.groovy b/src/main/groovy/com/infullmobile/toolkit/impl/android/commands/variant/ConfigureTestsForVariant.groovy new file mode 100644 index 0000000..406aa68 --- /dev/null +++ b/src/main/groovy/com/infullmobile/toolkit/impl/android/commands/variant/ConfigureTestsForVariant.groovy @@ -0,0 +1,37 @@ +package com.infullmobile.toolkit.impl.android.commands.variant + +import com.infullmobile.toolkit.impl.android.IVariantConfigCommand +import com.infullmobile.toolkit.impl.android.TestVariantWrapper +import com.infullmobile.toolkit.impl.android.VariantConfigurator +import com.infullmobile.toolkit.types.IProjectConfigurator + +/** + * Created by Adam Kobus on 26.09.2016. + * Copyright (c) 2016, inFullMobile + * License: MIT, file: /LICENSE + */ +class ConfigureTestsForVariant extends IVariantConfigCommand { + + @Override + boolean isCommandAllowed(IProjectConfigurator configurator) { + return config.configureTests; + } + + @Override + protected performCommandWith(VariantConfigurator variantConfigurator) { + variantWrapper.testVariants.each { TestVariantWrapper testVariant -> + def variant = testVariant.variant + def variantData = variant.variantData + String taskDependency; + def boolean isConnected = (testVariant.type == TestVariantWrapper.TestType.CONNECTED) + + if (isConnected) { + taskDependency = variantData.connectedTestTask.name + } else { + taskDependency = "test${variantData.variantDependency.name.capitalize()}" + } + def task = configuredProject.tasks.findByPath(taskDependency) + task.ignoreFailures = config.ignoreTestErrors + } + } +}