Skip to content

Problems with async test #1273

@BrunoMazzo

Description

@BrunoMazzo

Hi, I'm having problems when using an async test with KIF. I was able to create a simple app with one tests that always pass if the test is a sync function, but always fails if it is an async func:

struct ContentView: View {
    
    @State var showAlert = false
    @State var showSheet = false
    
    var body: some View {
        NavigationView {
            VStack {
                Button {
                    showAlert = true
                } label: {
                    Text("Show alert")
                }
                .alert("Alert", isPresented: $showAlert) {
                    Button {
                        showSheet = true
                    } label: {
                        Text("Show sheet")
                    }
                }
                .sheet(isPresented: $showSheet) {
                    Text("Hello world")
                }
            }
            .padding()
        }
    }
}
final class kifasyncTests: KIFTestCase {
    
    @MainActor
    func testAsyncMethod() async throws {
        // iOS 15.5 and 16.2 Always fails here. Nothing happens
        tester().tapView(withAccessibilityLabel: "Show alert")
        
        // iOS 15.4 Always fails here. I cannot see the alert button press
        tester().tapView(withAccessibilityLabel: "Show sheet")
        
        // iOS 16.0 Always fails here. I can see the alert button being press but the alert never dismiss
        try! tester().tryFindingView(withAccessibilityLabel: "Hello world")
    }
    
    //Always pass without any warning
    func testSyncMethod() {
        tester().tapView(withAccessibilityLabel: "Show alert")
        
        tester().tapView(withAccessibilityLabel: "Show sheet")
        
        try! tester().tryFindingView(withAccessibilityLabel: "Hello world")
    }
}

I'm able to reproduce the error with iOS 15.4, 15.5, 16.0 and 16.2 simulators (didn't test early versions) and with a real device with iOS 16.2. I'm using Xcode 14.2 and the latests KIF version from master.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions