Skip to content

Commit

Permalink
Merge pull request #65 from badoo/fix_test_method_annotation_support
Browse files Browse the repository at this point in the history
Fix for loosing test method annotations in test results
  • Loading branch information
idyatlov authored Jul 18, 2024
2 parents eeff970 + d7c7bc6 commit cd41335
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 31 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object Versions {
val testContainers = "1.15.3"
val jupiterEngine = "5.1.0"
val scalr = "4.2"
val allureJava = "2.17.3"
val allureJava = "2.28.0"
val allureEnvironment = "1.0.0"
val mockitoKotlin = "4.0.0"
val koin = "2.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.TestBody
import org.jetbrains.spek.api.dsl.given
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import org.koin.core.context.stopKoin
import java.io.File

Expand All @@ -34,12 +33,8 @@ class CacheScenarios : Spek(
container.stop()
}

afterEachTest {
stopKoin()
}

given("cache is enabled") {
on("the first execution of the test") {
group("the first execution of the test") {
it("should execute the test") {
val outputDir = runMarathonWithOneTest(
test = Test("test", "ExampleTest", "test", emptySet(), TestComponentInfo()),
Expand All @@ -54,7 +49,7 @@ class CacheScenarios : Spek(
}
}

on("the second execution of the test") {
group("the second execution of the test") {
it("should restored the test from cache") {
runMarathonWithOneTest(
test = Test("test", "SimpleTest", "test", emptySet(), TestComponentInfo()),
Expand Down Expand Up @@ -111,5 +106,7 @@ private fun TestBody.runMarathonWithOneTest(

marathon.runAsync()

stopKoin()

output!!
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class GradleHttpCacheService(private val configuration: RemoteCacheConfiguration
try {
val response = httpClient.get(url = key.entryUrl())
if (response.status != HttpStatusCode.OK) {
logger.warn("Got response status when loading cache entry for ${key.key} : ${response.status}")
if (response.status != HttpStatusCode.NotFound) {
logger.warn("Got response status when loading cache entry for ${key.key} : ${response.status}")
}
false
} else {
reader.readFrom(response.bodyAsChannel())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import io.qameta.allure.Epic
import io.qameta.allure.Feature
import io.qameta.allure.FileSystemResultsWriter
import io.qameta.allure.Issue
import io.qameta.allure.Lead
import io.qameta.allure.Owner
import io.qameta.allure.Severity
import io.qameta.allure.SeverityLevel
Expand Down Expand Up @@ -136,8 +137,8 @@ class AllureReporter(
.setTrace(testResult.stacktrace)

test.findValue<String>(Description::class.java.canonicalName)?.let { allureTestResult.setDescription(it) }
test.findValue<String>(Issue::class.java.canonicalName)?.let { allureTestResult.links.add(it.toLink()) }
test.findValue<String>(TmsLink::class.java.canonicalName)?.let { allureTestResult.links.add(it.toLink()) }
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.addAll(test.getOptionalLabels())

Expand All @@ -155,17 +156,13 @@ class AllureReporter(
findValue<String>(Story::class.java.canonicalName)?.let { list.add(ResultsUtils.createStoryLabel(it)) }
findValue<SeverityLevel>(Severity::class.java.canonicalName)?.let { list.add(ResultsUtils.createSeverityLabel(it)) }
findValue<String>(Owner::class.java.canonicalName)?.let { list.add(ResultsUtils.createOwnerLabel(it)) }
findValue<String>(Lead::class.java.canonicalName)?.let { list.add(ResultsUtils.createLabel(ResultsUtils.LEAD_LABEL_NAME, it)) }
findValue<String>("io.qameta.allure.junit4.Tag")?.let { list.add(ResultsUtils.createTagLabel(it)) }
findValue<String>("io.qameta.allure.Layer")?.let { list.add(ResultsUtils.createLabel("layer", it)) }

return list
}

private fun String.toLink(): io.qameta.allure.model.Link {
return io.qameta.allure.model.Link().also {
it.name = "Issue"
it.url = this
}
}

private inline fun <reified T> Test.findValue(name: String): T? {
metaProperties.find { it.name == name }?.let { property ->
return property.values["value"] as? T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import org.amshove.kluent.mock
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.given
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import org.mockito.kotlin.inOrder
import org.mockito.kotlin.reset
import org.mockito.kotlin.verifyNoMoreInteractions
Expand Down Expand Up @@ -69,7 +68,7 @@ object TestResultReporterSpec : Spek(
}

given("a reporter with a default config") {
on("success - failure - failure") {
group("success - failure - failure") {
it("should report success") {
val filter = filterDefault()

Expand All @@ -90,7 +89,7 @@ object TestResultReporterSpec : Spek(
}
}

on("failure - failure - success") {
group("failure - failure - success") {
it("should report success") {
val filter = filterDefault()

Expand All @@ -113,7 +112,7 @@ object TestResultReporterSpec : Spek(
}

given("a reporter with a strict config") {
on("success - failure - failure") {
group("success - failure - failure") {
it("should report failure") {
val reporter = strictReporter()

Expand All @@ -134,7 +133,7 @@ object TestResultReporterSpec : Spek(
}
}

on("failure - success - success") {
group("failure - success - success") {
it("should report failure") {
val filter = strictReporter()

Expand All @@ -157,7 +156,7 @@ object TestResultReporterSpec : Spek(
}

given("a reporter with a strict run filter when test matches filter") {
on("success - failure - failure") {
group("success - failure - failure") {
it("should report failure") {
val reporter = strictFilterReporter(filter = SimpleClassnameFilter(Regex.fromLiteral(test.clazz)))

Expand All @@ -178,7 +177,7 @@ object TestResultReporterSpec : Spek(
}
}

on("failure - success - success") {
group("failure - success - success") {
it("should report failure") {
val reporter = strictFilterReporter(filter = SimpleClassnameFilter(Regex.fromLiteral(test.clazz)))

Expand All @@ -201,7 +200,7 @@ object TestResultReporterSpec : Spek(
}

given("a reporter with a strict run filter when test does not match filter") {
on("success - failure - failure") {
group("success - failure - failure") {
it("should report success") {
val reporter = strictFilterReporter(filter = SimpleClassnameFilter(Regex.fromLiteral("$^")))

Expand All @@ -222,7 +221,7 @@ object TestResultReporterSpec : Spek(
}
}

on("failure - success - success") {
group("failure - success - success") {
it("should report success") {
val reporter = strictFilterReporter(filter = SimpleClassnameFilter(Regex.fromLiteral("$^")))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class TestRunResultsListener(
}

private fun Map.Entry<Test, AndroidTestResult>.toTestResult(device: Device): TestResult {
val testInstanceFromBatch = testBatch.tests.find { "${it.pkg}.${it.clazz}" == key.clazz && it.method == key.method }
val testInstanceFromBatch = testBatch.tests.find { it == key }
val test = key
val attachments = attachments[test] ?: emptyList<Attachment>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import org.amshove.kluent.shouldBeEqualTo
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import java.io.File

class AndroidTestParserSpek : Spek(
{
describe("android test parser") {
val parser = AndroidTestParser()

on("android test apk") {
group("android test apk") {
val apkFile = File(javaClass.classLoader.getResource("android_test_1.apk").file)
val configuration = Configuration(
name = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import java.time.Clock
class AndroidDeviceProviderSpek : Spek(
{
given("A provider") {
on("terminate") {
group("terminate") {
it("should close the channel") {
val config = ConfigurationFactory().build()
val provider = DdmlibDeviceProvider(Track(), SystemTimer(Clock.systemDefaultZone()), config, mock(), mock(), mock(), mock(), mock())
Expand Down

0 comments on commit cd41335

Please sign in to comment.