Search code examples
swiftxctest

How to set parameter to a XCUITest test case do prepare for data driven testing


Is it possible to have parameter for a test case like:

func testExample1(term: String) {

  XCTContext.runActivity(named: "Search for \(term)") { activity in
        // Enter text in the search field
    let textField = XCUIApplication().otherElements.containing(.button, identifier:"Button").children(matching: .textField).element
    textField.tap()
    textField.typeText(term)
  }

As soon as I change my test case to get parameter, the XCUItest change it from test case to class function.

I need to do the following call (or something like that):

xcodebuild test -project MyLib.xcodeproj -scheme MyAppUITests -destination 'platform=iOS Simulator,OS=11.3,name=iPhone 5s' -only-testing:MyAppUITests/MyAppUITests/testExample1("toto")|xcpretty --test --color

Solution

  • Sadly, XCTest has no support for parameterized testing.

    (Will that change at this year's WWDC? I keep hoping, every year…)