Skip to content
New issue

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

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

Already on GitHub? # to your account

feat: added support for JUnit Theory tests #1968

Merged
merged 4 commits into from
May 26, 2021
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
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import ftl.shard.TestMethod as ShardTestMethod

suspend fun AndroidArgs.createAndroidTestContexts(): List<AndroidTestContext> = resolveApks().setupShards(this)

private val customTestAnnotations = listOf("org.junit.experimental.theories.Theory")

private suspend fun List<AndroidTestContext>.setupShards(
args: AndroidArgs,
testFilter: TestFilter = TestFilters.fromTestTargets(args.testTargets, args.testTargetsForShard)
Expand Down Expand Up @@ -118,7 +120,8 @@ internal fun InstrumentationTestContext.getFlankTestMethods(
testFilter: TestFilter
): List<FlankTestMethod> =
getParametrizedClasses().let { parameterizedClasses: List<TestMethod> ->
DexParser.findTestMethods(test.local).asSequence()
DexParser.findTestMethods(test.local, customTestAnnotations)
.asSequence()
.distinctBy { it.testName }
.filter(testFilter.shouldRun)
.filterNot(parameterizedClasses::belong)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ class CreateAndroidTestContextKtTest {
assertEquals(expected, actual)
}

@Test
fun `should pick up @Theory tests`() {
val testInstrumentationContext = InstrumentationTestContext(
FileReference("", ""),
FileReference("../test_projects/android/apks/app-theory-androidTest.apk", "")
)

val parsedTests = testInstrumentationContext
.getFlankTestMethods(TestFilter("filter", shouldRun = { true }))
.map { it.testName }
.map { it.substringAfterLast("#") }
.toSet()

assertTrue(parsedTests.isNotEmpty())
assertTrue(parsedTests.contains("exampleTheoryTest"))
}

@Test
fun `should filter out methods by distinct name`() {
// given
Expand All @@ -84,7 +101,7 @@ class CreateAndroidTestContextKtTest {

// when
mockkObject(DexParser) {
every { findTestMethods(any()) } returns listOf(
every { findTestMethods(any(), any()) } returns listOf(
TestMethod("testMethod", listOf(mockk(relaxed = true))),
TestMethod("testMethod", listOf(mockk(relaxed = true))),
TestMethod("testMethod", listOf()),
Expand All @@ -110,7 +127,7 @@ class CreateAndroidTestContextKtTest {
)

mockkObject(DexParser) {
every { findTestMethods(any()) } returns listOf(
every { findTestMethods(any(), any()) } returns listOf(
TestMethod("foo.bar.TestClass1#test1", emptyList()),
TestMethod("foo.bar.TestClass1#test2", emptyList()),
TestMethod("foo.bar.TestClass2#test1", emptyList()),
Expand Down