Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
igorsmotto committed Nov 26, 2024
1 parent 051bff7 commit 715bcc8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
1 change: 1 addition & 0 deletions maestro-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
23 changes: 6 additions & 17 deletions maestro-client/src/test/java/maestro/ios/MockXCTestInstaller.kt
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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) {
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<XCTestStarter>()

@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
Expand All @@ -35,6 +48,7 @@ class XCTestDriverClientTest {
val mockXCTestInstaller = MockXCTestInstaller(simulator)
val xcTestDriverClient = XCTestDriverClient(
mockXCTestInstaller,
mockXCTestStarter,
XCTestClient("localhost", 22087)
)

Expand Down Expand Up @@ -65,6 +79,7 @@ class XCTestDriverClientTest {
val mockXCTestInstaller = MockXCTestInstaller(simulator)
val xcTestDriverClient = XCTestDriverClient(
mockXCTestInstaller,
mockXCTestStarter,
XCTestClient("localhost", 22087)
)

Expand Down Expand Up @@ -96,6 +111,7 @@ class XCTestDriverClientTest {
val mockXCTestInstaller = MockXCTestInstaller(simulator)
val xcTestDriverClient = XCTestDriverClient(
mockXCTestInstaller,
mockXCTestStarter,
XCTestClient("localhost", 22087)
)
val actualDeviceInfo = xcTestDriverClient.deviceInfo(httpUrl)
Expand Down Expand Up @@ -126,6 +142,7 @@ class XCTestDriverClientTest {
val mockXCTestInstaller = MockXCTestInstaller(simulator)
val xcTestDriverClient = XCTestDriverClient(
mockXCTestInstaller,
mockXCTestStarter,
XCTestClient("localhost", 22087)
)

Expand Down Expand Up @@ -157,6 +174,7 @@ class XCTestDriverClientTest {
val mockXCTestInstaller = MockXCTestInstaller(simulator)
val xcTestDriverClient = XCTestDriverClient(
mockXCTestInstaller,
mockXCTestStarter,
XCTestClient("localhost", 22087)
)

Expand Down Expand Up @@ -188,6 +206,7 @@ class XCTestDriverClientTest {
val mockXCTestInstaller = MockXCTestInstaller(simulator)
val xcTestDriverClient = XCTestDriverClient(
mockXCTestInstaller,
mockXCTestStarter,
XCTestClient("localhost", 22087)
)

Expand Down

0 comments on commit 715bcc8

Please sign in to comment.