diff --git a/test_projects/android/apks/app-theory-androidTest.apk b/test_projects/android/apks/app-theory-androidTest.apk new file mode 100644 index 0000000000..672b40d35b Binary files /dev/null and b/test_projects/android/apks/app-theory-androidTest.apk differ 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 c596c7be0d..57fd79ea82 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 @@ -33,6 +33,8 @@ import ftl.shard.TestMethod as ShardTestMethod suspend fun AndroidArgs.createAndroidTestContexts(): List = resolveApks().setupShards(this) +private val customTestAnnotations = listOf("org.junit.experimental.theories.Theory") + private suspend fun List.setupShards( args: AndroidArgs, testFilter: TestFilter = TestFilters.fromTestTargets(args.testTargets, args.testTargetsForShard) @@ -118,7 +120,8 @@ internal fun InstrumentationTestContext.getFlankTestMethods( testFilter: TestFilter ): List = getParametrizedClasses().let { parameterizedClasses: List -> - DexParser.findTestMethods(test.local).asSequence() + DexParser.findTestMethods(test.local, customTestAnnotations) + .asSequence() .distinctBy { it.testName } .filter(testFilter.shouldRun) .filterNot(parameterizedClasses::belong) 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 b3646ad20c..9e0ec8dc55 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 @@ -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 @@ -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()), @@ -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()),