Search code examples
iosswiftxcode-ui-testingui-testing

Run iterative tests in XCTestCase on the same test


I am attempting to run a UI Test in XCTestCase and when I am running it, I would like to run it multiple times with multiple different inputs. Is there a straightforward way to run a test multiple times with different inputs?

I want to run a test with different inputs but only write the test once. An example of this would be that I am trying to pass different user names in to verify behavior.


Solution

  • It's kind of sloppy because it executes setUp() once at the beginning unnecessarily but otherwise it gets the job done...

    func testLoop() { 
        for parameter in myParameters {
           setUp()
           testToBeLooped(parameter: parameter)
           tearDown()
        }
    }