swiftuixctestxctestcase

Access Button Tap In Unit test SwiftUI


I'm trying to access the button click in the Unit test class. I'm not able to perform action.

Button AppCode:-

var body: some View {
    VStack(spacing: 10) {
        Button(action: {
            print("Button Cicked")
        }) {
            Text("Testing")
                .frame(width: 50, height: 20)
                .padding()
                .foregroundColor(.white)
                .cornerRadius(40)
                .accessibility(label: Text("Testing"))
        }
        Spacer()
    }
}

Unit Class Code:-

class testBtnClickked: XCTestCase {

func testtestBtnClickked() {
    let app = XCUIApplication()
    let deleteButton = app.buttons["Testing"]
    deleteButton.click()    
  }
}

Error:- No target application path specified via test configuration: <XCTestConfiguration: 0x7fb315a11a80>

ScreenShot

Can someone please explain to me how to access the button click in the XCTest Class, I've tried to with above code but no results yet.

Any help would be greatly appreciated.

Thanks in advance.


Solution

  • This issue occurs, because i'm not using the UI test class. I'm using UI test code in the Unit Class. After Create the Different UI test Class, the same code working perfectly.