Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelpasterz committed Oct 12, 2020
1 parent 7585eaa commit f1c3ef4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ private val ignoredAnnotations = listOf(

private fun String.toFlankTestMethod() = FlankTestMethod("class $this", ignored = false, isParameterizedClass = true)

private fun InstrumentationTestContext.getParametrizedClasses(): List<String> =
@VisibleForTesting
internal fun InstrumentationTestContext.getParametrizedClasses(): List<String> =
DexParser.readDexFiles(test.local).fold(emptyList()) { accumulator, file: DexFile ->
accumulator + file.classDefs
.filter(file::isParametrizedClass)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package ftl.run.platform.android

import com.google.common.truth.Truth.assertThat
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.filter.TestFilters
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 ftl.util.FlankTestMethod
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkObject
import io.mockk.mockkStatic
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Test
Expand Down Expand Up @@ -79,4 +83,32 @@ class CreateAndroidTestContextKtTest {
// given
assertEquals(actual, 2)
}

@Test
fun `should not append all parameterized classes to list of test methods`() {
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", "")
)

mockkStatic("ftl.run.platform.android.CreateAndroidTestContextKt") {
every { testInstrumentationContext.getParametrizedClasses() } returns listOf("foo.bar.ParamClass")
}
mockkObject(DexParser) {
every { findTestMethods(any()) } returns listOf(
TestMethod("foo.bar.TestClass1#test1", emptyList()),
TestMethod("foo.bar.TestClass1#test2", emptyList()),
TestMethod("foo.bar.TestClass2#test1", emptyList()),
TestMethod("foo.bar.TestClass2#test2", emptyList()),
TestMethod("foo.bar.ParamClass#testParam", emptyList()),
)

val actual = testInstrumentationContext.getFlankTestMethods(TestFilters.fromTestTargets(listOf("class foo.bar.TestClass1")))
val expected = listOf(
FlankTestMethod("class foo.bar.TestClass1#test1"),
FlankTestMethod("class foo.bar.TestClass1#test2")
)
assertThat(actual).isEqualTo(expected)
}
}
}

0 comments on commit f1c3ef4

Please # to comment.