diff --git a/maestro-client/build.gradle.kts b/maestro-client/build.gradle.kts index fd765d8eb2..7eefc52ba2 100644 --- a/maestro-client/build.gradle.kts +++ b/maestro-client/build.gradle.kts @@ -92,6 +92,7 @@ dependencies { testRuntimeOnly(libs.junit.jupiter.engine) testImplementation(libs.google.truth) testImplementation(libs.square.mock.server) + testImplementation(libs.mockk) testImplementation(libs.junit.jupiter.params) } diff --git a/maestro-client/src/test/java/maestro/ios/MockXCTestInstaller.kt b/maestro-client/src/test/java/maestro/ios/MockXCTestInstaller.kt index 553e417688..950764d37a 100644 --- a/maestro-client/src/test/java/maestro/ios/MockXCTestInstaller.kt +++ b/maestro-client/src/test/java/maestro/ios/MockXCTestInstaller.kt @@ -1,6 +1,7 @@ package maestro.ios import com.google.common.truth.Truth.assertThat +import java.io.File import xcuitest.XCTestClient import xcuitest.installer.XCTestInstaller @@ -10,30 +11,20 @@ class MockXCTestInstaller( private var attempts = 0 - override fun install(): XCTestClient? { + override fun install(): File { attempts++ for (i in 0..simulator.installationRetryCount) { assertThat(simulator.runningApps()).doesNotContain("dev.mobile.maestro-driver-iosUITests.xctrunner") } - return if (simulator.shouldInstall) { + if (simulator.shouldInstall) { simulator.installXCTestDriver() - XCTestClient("localhost", 22807) - } else { - null } + return File("xctestrun") } - override fun uninstall(): Boolean { - simulator.uninstallXCTestDriver() - return true - } - - override fun isChannelAlive(): Boolean { - return simulator.isXCTestRunnerAlive() - } - - override fun close() { + override fun uninstall() { simulator.uninstallXCTestDriver() + return } fun assertInstallationRetries(expectedRetries: Int) { @@ -49,8 +40,6 @@ class MockXCTestInstaller( fun runningApps() = runningApps - fun isXCTestRunnerAlive() = runningApps.contains("dev.mobile.maestro-driver-iosUITests.xctrunner") - fun uninstallXCTestDriver() = runningApps.clear() fun installXCTestDriver() = runningApps.add("dev.mobile.maestro-driver-iosUITests.xctrunner") diff --git a/maestro-client/src/test/java/maestro/xctestdriver/XCTestDriverClientTest.kt b/maestro-client/src/test/java/maestro/xctestdriver/XCTestDriverClientTest.kt index 89bf0a9544..9027cfb1a1 100644 --- a/maestro-client/src/test/java/maestro/xctestdriver/XCTestDriverClientTest.kt +++ b/maestro-client/src/test/java/maestro/xctestdriver/XCTestDriverClientTest.kt @@ -2,6 +2,9 @@ package maestro.xctestdriver import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.google.common.truth.Truth.assertThat +import io.mockk.clearMocks +import io.mockk.every +import io.mockk.mockk import maestro.ios.MockXCTestInstaller import maestro.utils.network.XCUITestServerError import okhttp3.mockwebserver.MockResponse @@ -16,9 +19,19 @@ import xcuitest.XCTestDriverClient import xcuitest.api.DeviceInfo import xcuitest.api.Error import java.net.InetAddress +import org.junit.jupiter.api.BeforeEach +import xcuitest.starter.XCTestStarter class XCTestDriverClientTest { + private val mockXCTestStarter = mockk() + + @BeforeEach + fun setup() { + clearMocks(mockXCTestStarter) + every { mockXCTestStarter.start(any()) } returns XCTestClient("localhost", 22087) + } + @Test fun `it should return correct message in case of TimeoutException with 3 retries`() { // given @@ -35,6 +48,7 @@ class XCTestDriverClientTest { val mockXCTestInstaller = MockXCTestInstaller(simulator) val xcTestDriverClient = XCTestDriverClient( mockXCTestInstaller, + mockXCTestStarter, XCTestClient("localhost", 22087) ) @@ -65,6 +79,7 @@ class XCTestDriverClientTest { val mockXCTestInstaller = MockXCTestInstaller(simulator) val xcTestDriverClient = XCTestDriverClient( mockXCTestInstaller, + mockXCTestStarter, XCTestClient("localhost", 22087) ) @@ -96,6 +111,7 @@ class XCTestDriverClientTest { val mockXCTestInstaller = MockXCTestInstaller(simulator) val xcTestDriverClient = XCTestDriverClient( mockXCTestInstaller, + mockXCTestStarter, XCTestClient("localhost", 22087) ) val actualDeviceInfo = xcTestDriverClient.deviceInfo(httpUrl) @@ -126,6 +142,7 @@ class XCTestDriverClientTest { val mockXCTestInstaller = MockXCTestInstaller(simulator) val xcTestDriverClient = XCTestDriverClient( mockXCTestInstaller, + mockXCTestStarter, XCTestClient("localhost", 22087) ) @@ -157,6 +174,7 @@ class XCTestDriverClientTest { val mockXCTestInstaller = MockXCTestInstaller(simulator) val xcTestDriverClient = XCTestDriverClient( mockXCTestInstaller, + mockXCTestStarter, XCTestClient("localhost", 22087) ) @@ -188,6 +206,7 @@ class XCTestDriverClientTest { val mockXCTestInstaller = MockXCTestInstaller(simulator) val xcTestDriverClient = XCTestDriverClient( mockXCTestInstaller, + mockXCTestStarter, XCTestClient("localhost", 22087) )