From f152615fc5c51605a8d1d2c50ae6c14acf903946 Mon Sep 17 00:00:00 2001 From: Ivan Dyatlov Date: Sun, 12 Jan 2025 15:17:20 +0000 Subject: [PATCH] Add support for application and component tests in Allure --- .../marathon/execution/Configuration.kt | 3 +++ .../marathon/report/allure/AllureReporter.kt | 20 ++++++++++++++++--- .../marathon/ConfigurationFactory.kt | 1 + .../malinskiy/marathon/MarathonExtension.kt | 5 +++++ .../android/AndroidDeviceTestRunnerSpek.kt | 1 + .../test/factory/ConfigurationFactory.kt | 2 ++ 6 files changed, 29 insertions(+), 3 deletions(-) diff --git a/core/src/main/kotlin/com/malinskiy/marathon/execution/Configuration.kt b/core/src/main/kotlin/com/malinskiy/marathon/execution/Configuration.kt index 072379349..4d08fba1f 100644 --- a/core/src/main/kotlin/com/malinskiy/marathon/execution/Configuration.kt +++ b/core/src/main/kotlin/com/malinskiy/marathon/execution/Configuration.kt @@ -41,6 +41,7 @@ data class Configuration( val testClassRegexes: Collection, val ignoreFailureRegexes: Collection, val failFastFailureRegexes: Collection, + val appModuleRegexes: Collection, val testOutputTimeoutMillis: Long, val noDevicesTimeoutMillis: Long, @@ -72,6 +73,7 @@ data class Configuration( testClassRegexes: Collection?, ignoreFailureRegexes: Collection?, failFastFailureRegexes: Collection?, + appModuleRegexes: Collection?, testOutputTimeoutMillis: Long?, noDevicesTimeoutMillis: Long?, @@ -100,6 +102,7 @@ data class Configuration( testClassRegexes = testClassRegexes ?: listOf(Regex("^((?!Abstract).)*Test$")), ignoreFailureRegexes = ignoreFailureRegexes ?: emptyList(), failFastFailureRegexes = failFastFailureRegexes ?: emptyList(), + appModuleRegexes = appModuleRegexes ?: emptyList(), testOutputTimeoutMillis = testOutputTimeoutMillis ?: DEFAULT_OUTPUT_TIMEOUT_MILLIS, noDevicesTimeoutMillis = noDevicesTimeoutMillis ?: DEFAULT_NO_DEVICES_TIMEOUT_MILLIS, analyticsTracker = analyticsTracker, diff --git a/core/src/main/kotlin/com/malinskiy/marathon/report/allure/AllureReporter.kt b/core/src/main/kotlin/com/malinskiy/marathon/report/allure/AllureReporter.kt index 90b34e7f4..acfa6b057 100644 --- a/core/src/main/kotlin/com/malinskiy/marathon/report/allure/AllureReporter.kt +++ b/core/src/main/kotlin/com/malinskiy/marathon/report/allure/AllureReporter.kt @@ -59,7 +59,7 @@ class AllureReporter( params.forEach { params[it.key] = it.value } - params["platform"] = "Android" + params[PLATFORM] = ANDROID params.saveToEnvironmentProperties() } @@ -154,14 +154,23 @@ class AllureReporter( test.findValue(Description::class.java.canonicalName)?.let { allureTestResult.setDescription(it) } test.findValue(Issue::class.java.canonicalName)?.let { allureTestResult.links.add(ResultsUtils.createIssueLink(it)) } test.findValue(TmsLink::class.java.canonicalName)?.let { allureTestResult.links.add(ResultsUtils.createTmsLink(it)) } - allureTestResult.labels.add(ResultsUtils.createLabel("layer", "UI")) - allureTestResult.labels.add(ResultsUtils.createLabel("platform", "Android")) + + allureTestResult.labels.add( + ResultsUtils.createLabel( + LAYER, if (test.isApplicationTest()) CLIENT_APPLICATION else CLIENT_COMPONENT + ) + ) + + allureTestResult.labels.add(ResultsUtils.createLabel(PLATFORM, ANDROID)) allureTestResult.labels.addAll(ResultsUtils.getProvidedLabels()) allureTestResult.labels.addAll(test.getOptionalLabels()) return allureTestResult } + private fun Test.isApplicationTest(): Boolean = + configuration.appModuleRegexes.any { it.matches(pkg) } + private fun getHistoryId(test: Test): String = ResultsUtils.generateMethodSignatureHash(test.clazz, test.method, emptyList()) @@ -192,5 +201,10 @@ class AllureReporter( private companion object { private const val MESSAGE_LINES_COUNT = 3 + private const val LAYER = "layer" + private const val PLATFORM = "platform" + private const val ANDROID = "Android" + private const val CLIENT_APPLICATION = "Application client" + private const val CLIENT_COMPONENT = "Component client" } } diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/ConfigurationFactory.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/ConfigurationFactory.kt index 70dcffd45..d5618022b 100644 --- a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/ConfigurationFactory.kt +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/ConfigurationFactory.kt @@ -29,6 +29,7 @@ internal fun createCommonConfiguration( testClassRegexes = extensionConfig.testClassRegexes.get().map { it.toRegex() }, ignoreFailureRegexes = extensionConfig.ignoreFailureRegexes.get().map { it.toRegex(RegexOption.DOT_MATCHES_ALL) }, failFastFailureRegexes = extensionConfig.failFastFailureRegexes.get().map { it.toRegex(RegexOption.DOT_MATCHES_ALL) }, + appModuleRegexes = extensionConfig.appModuleRegexes.get().map { it.toRegex(RegexOption.DOT_MATCHES_ALL) }, testOutputTimeoutMillis = extensionConfig.testOutputTimeoutMillis.orNull, noDevicesTimeoutMillis = extensionConfig.noDevicesTimeoutMillis.orNull, analyticsTracker = MarathonListenerHolder.analyticsTracker, diff --git a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/MarathonExtension.kt b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/MarathonExtension.kt index b69ce93e1..75b00fd7d 100644 --- a/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/MarathonExtension.kt +++ b/marathon-gradle-plugin/src/main/kotlin/com/malinskiy/marathon/MarathonExtension.kt @@ -62,6 +62,11 @@ interface MarathonExtension { */ val failFastFailureRegexes: ListProperty + /** + * Application modules, needed for distinguish between application and component tests in Allure + */ + val appModuleRegexes: ListProperty + val uncompletedTestRetryQuota: Property val usedStorageThresholdInPercents: Property val testOutputTimeoutMillis: Property diff --git a/vendor/vendor-android/ddmlib/src/test/kotlin/com/malinskiy/marathon/android/AndroidDeviceTestRunnerSpek.kt b/vendor/vendor-android/ddmlib/src/test/kotlin/com/malinskiy/marathon/android/AndroidDeviceTestRunnerSpek.kt index 1bac21772..9aca5db86 100644 --- a/vendor/vendor-android/ddmlib/src/test/kotlin/com/malinskiy/marathon/android/AndroidDeviceTestRunnerSpek.kt +++ b/vendor/vendor-android/ddmlib/src/test/kotlin/com/malinskiy/marathon/android/AndroidDeviceTestRunnerSpek.kt @@ -66,6 +66,7 @@ class AndroidDeviceTestRunnerSpek : Spek({ excludeSerialRegexes = null, ignoreFailureRegexes = null, failFastFailureRegexes = null, + appModuleRegexes = null, testOutputTimeoutMillis = null, noDevicesTimeoutMillis = null, analyticsTracker = null, diff --git a/vendor/vendor-test/src/main/kotlin/com/malinskiy/marathon/test/factory/ConfigurationFactory.kt b/vendor/vendor-test/src/main/kotlin/com/malinskiy/marathon/test/factory/ConfigurationFactory.kt index e1e2125e0..e893c0479 100644 --- a/vendor/vendor-test/src/main/kotlin/com/malinskiy/marathon/test/factory/ConfigurationFactory.kt +++ b/vendor/vendor-test/src/main/kotlin/com/malinskiy/marathon/test/factory/ConfigurationFactory.kt @@ -40,6 +40,7 @@ class ConfigurationFactory { var testClassRegexes: Collection? = null var ignoreFailureRegexes: List? = null var failFastFailureRegexes: List? = null + var appModuleRegexes: List? = null var testOutputTimeoutMillis: Long? = null var noDevicesTimeoutMillis: Long? = null var analyticsTracker: Tracker? = null @@ -76,6 +77,7 @@ class ConfigurationFactory { testClassRegexes = testClassRegexes, ignoreFailureRegexes = ignoreFailureRegexes, failFastFailureRegexes = failFastFailureRegexes, + appModuleRegexes = appModuleRegexes, testOutputTimeoutMillis = testOutputTimeoutMillis, noDevicesTimeoutMillis = noDevicesTimeoutMillis, analyticsTracker = analyticsTracker,