Skip to content

Commit

Permalink
Add support for application and component tests in Allure
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Dyatlov committed Jan 12, 2025
1 parent 27cc6da commit f152615
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ data class Configuration(
val testClassRegexes: Collection<Regex>,
val ignoreFailureRegexes: Collection<Regex>,
val failFastFailureRegexes: Collection<Regex>,
val appModuleRegexes: Collection<Regex>,

val testOutputTimeoutMillis: Long,
val noDevicesTimeoutMillis: Long,
Expand Down Expand Up @@ -72,6 +73,7 @@ data class Configuration(
testClassRegexes: Collection<Regex>?,
ignoreFailureRegexes: Collection<Regex>?,
failFastFailureRegexes: Collection<Regex>?,
appModuleRegexes: Collection<Regex>?,

testOutputTimeoutMillis: Long?,
noDevicesTimeoutMillis: Long?,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AllureReporter(
params.forEach {
params[it.key] = it.value
}
params["platform"] = "Android"
params[PLATFORM] = ANDROID
params.saveToEnvironmentProperties()
}

Expand Down Expand Up @@ -154,14 +154,23 @@ class AllureReporter(
test.findValue<String>(Description::class.java.canonicalName)?.let { allureTestResult.setDescription(it) }
test.findValue<String>(Issue::class.java.canonicalName)?.let { allureTestResult.links.add(ResultsUtils.createIssueLink(it)) }
test.findValue<String>(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())

Expand Down Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ interface MarathonExtension {
*/
val failFastFailureRegexes: ListProperty<String>

/**
* Application modules, needed for distinguish between application and component tests in Allure
*/
val appModuleRegexes: ListProperty<String>

val uncompletedTestRetryQuota: Property<Int>
val usedStorageThresholdInPercents: Property<Int>
val testOutputTimeoutMillis: Property<Long>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class AndroidDeviceTestRunnerSpek : Spek({
excludeSerialRegexes = null,
ignoreFailureRegexes = null,
failFastFailureRegexes = null,
appModuleRegexes = null,
testOutputTimeoutMillis = null,
noDevicesTimeoutMillis = null,
analyticsTracker = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ConfigurationFactory {
var testClassRegexes: Collection<Regex>? = null
var ignoreFailureRegexes: List<Regex>? = null
var failFastFailureRegexes: List<Regex>? = null
var appModuleRegexes: List<Regex>? = null
var testOutputTimeoutMillis: Long? = null
var noDevicesTimeoutMillis: Long? = null
var analyticsTracker: Tracker? = null
Expand Down Expand Up @@ -76,6 +77,7 @@ class ConfigurationFactory {
testClassRegexes = testClassRegexes,
ignoreFailureRegexes = ignoreFailureRegexes,
failFastFailureRegexes = failFastFailureRegexes,
appModuleRegexes = appModuleRegexes,
testOutputTimeoutMillis = testOutputTimeoutMillis,
noDevicesTimeoutMillis = noDevicesTimeoutMillis,
analyticsTracker = analyticsTracker,
Expand Down

0 comments on commit f152615

Please sign in to comment.