Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Added missing test t cover duplicated tests issue #1055

Merged
merged 1 commit into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -59,16 +60,17 @@ private fun InstrumentationTestContext.calculateShards(
)
}

private fun InstrumentationTestContext.getFlankTestMethods(
@VisibleForTesting
internal fun InstrumentationTestContext.getFlankTestMethods(
testFilter: TestFilter
): List<FlankTestMethod> =
getParametrizedClasses().let { parameterizedClasses: List<String> ->
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<String>.belong(method: TestMethod) = any { className -> method.testName.startsWith(className) }
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
}
}