From 84e00c3e3744d7627cc550ed98c6f1c52ef07809 Mon Sep 17 00:00:00 2001 From: Piotr Adamczyk Date: Wed, 26 Aug 2020 17:31:12 +0200 Subject: [PATCH] tests: Added missing test t cover duplicated tests issue --- .../android/CreateAndroidTestContext.kt | 14 ++++--- .../android/CreateAndroidTestContextKtTest.kt | 37 +++++++++++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/test_runner/src/main/kotlin/ftl/run/platform/android/CreateAndroidTestContext.kt b/test_runner/src/main/kotlin/ftl/run/platform/android/CreateAndroidTestContext.kt index a45dd0e118..084686d22a 100644 --- a/test_runner/src/main/kotlin/ftl/run/platform/android/CreateAndroidTestContext.kt +++ b/test_runner/src/main/kotlin/ftl/run/platform/android/CreateAndroidTestContext.kt @@ -1,5 +1,6 @@ package ftl.run.platform.android +import com.google.common.annotations.VisibleForTesting import com.linkedin.dex.parser.DecodedValue import com.linkedin.dex.parser.DexParser import com.linkedin.dex.parser.TestAnnotation @@ -59,16 +60,17 @@ private fun InstrumentationTestContext.calculateShards( ) } -private fun InstrumentationTestContext.getFlankTestMethods( +@VisibleForTesting +internal fun InstrumentationTestContext.getFlankTestMethods( testFilter: TestFilter ): List = getParametrizedClasses().let { parameterizedClasses: List -> DexParser.findTestMethods(test.local).asSequence() - .distinctBy { it.testName } - .filter(testFilter.shouldRun) - .filterNot(parameterizedClasses::belong) - .map(TestMethod::toFlankTestMethod).toList() - .plus(parameterizedClasses.map(String::toFlankTestMethod)) + .distinctBy { it.testName } + .filter(testFilter.shouldRun) + .filterNot(parameterizedClasses::belong) + .map(TestMethod::toFlankTestMethod).toList() + .plus(parameterizedClasses.map(String::toFlankTestMethod)) } private fun List.belong(method: TestMethod) = any { className -> method.testName.startsWith(className) } diff --git a/test_runner/src/test/kotlin/ftl/run/platform/android/CreateAndroidTestContextKtTest.kt b/test_runner/src/test/kotlin/ftl/run/platform/android/CreateAndroidTestContextKtTest.kt index 1b2715d35e..04bc670632 100644 --- a/test_runner/src/test/kotlin/ftl/run/platform/android/CreateAndroidTestContextKtTest.kt +++ b/test_runner/src/test/kotlin/ftl/run/platform/android/CreateAndroidTestContextKtTest.kt @@ -1,11 +1,19 @@ package ftl.run.platform.android +import com.linkedin.dex.parser.DexParser +import com.linkedin.dex.parser.DexParser.Companion.findTestMethods +import com.linkedin.dex.parser.TestMethod import ftl.args.AndroidArgs +import ftl.filter.TestFilter import ftl.run.model.AndroidTestContext import ftl.run.model.InstrumentationTestContext import ftl.run.model.RoboTestContext import ftl.test.util.mixedConfigYaml import ftl.test.util.should +import ftl.util.FileReference +import io.mockk.every +import io.mockk.mockk +import io.mockk.mockkObject import kotlinx.coroutines.runBlocking import org.junit.Assert.assertEquals import org.junit.Test @@ -47,4 +55,33 @@ class CreateAndroidTestContextKtTest { // then assertEquals(expected, actual) } + + @Test + fun `Should filter out methods by distinct name`() { + // given + val testInstrumentationContext = InstrumentationTestContext( + FileReference("./src/test/kotlin/ftl/fixtures/tmp/apk/app-debug.apk", ""), + FileReference("./src/test/kotlin/ftl/fixtures/tmp/apk/app-single-success-debug-androidTest.apk", "") + ) + var actual = 0 + + // when + mockkObject(DexParser) { + every { findTestMethods(any()) } returns listOf( + TestMethod("testMethod", listOf(mockk(relaxed = true))), + TestMethod("testMethod", listOf(mockk(relaxed = true))), + TestMethod("testMethod", listOf()), + TestMethod("testMethod2", listOf(mockk(relaxed = true))), + TestMethod("testMethod2", listOf(mockk(relaxed = true))), + TestMethod("testMethod2", listOf()), + ) + + actual = testInstrumentationContext + .getFlankTestMethods(TestFilter("test", { true })) + .size + } + + // given + assertEquals(actual, 2) + } }