XCUITest Reset Application State

Curious how people are handling resetting application state in between tests. Thinking I could uninstall the app in the tear down possibly. If others are doing it please share. Thanks!


Jim

Post not yet marked as solved Up vote post of mos6y Down vote post of mos6y
17k views

Replies

I am also interested in any feedback if some one has done some device state management. I have a scenario where my application the first time you load it up and install it should give you a prompt, but having to reset the simulator everytime I run this test, is inefficient.


Has anyone had any experience working with setting, and managing various device states yet with the new UI Testing?

I am trying to run the below teardown code.


If I don't import the app I get.

"Use of unresolved identifer 'NSTask'


So If I try to import the app

@testable import MyApp

I get failed to import bridging header errors

But in my Unit Test target I don't get this error and I don't set the bridging header in the Unit Test target.




  override func tearDown() {
        super.tearDown()
    
        let task = NSTask()

        task.launchPath = "/usr/bin/xcrun"
        task.arguments = "simctl uninstall booted com.nike.omega-inhouse"
        task.launch()
    
    }

Any luck with this?

Fwiw, I ended up going this route (http://www.adamkaump.com/thoughts/uitests) and resetting the state of my app at runtime when appropriate.

big challenge I have been trying to solve is resetting the location permission back to null state. Only way I have found so far is uninstall the app, which I have not solved yet from xctest.

I filed this bug a couple weeks ago


Unable to reset simulator state between XCTestCase cases.

https://openradar.appspot.com/radar?id=5560321334837248

rdar://problem/22455111


Still waiting on a response.

I think that's a little bit unfair - you filed the radar on 8/27, and we got back to you with a follow up question on 8/31. The radar is assigned to the engineering team in question, and still open. Is there anything else that you're waiting for?

I put this as a Test Pre-Action script:


/usr/bin/xcrun simctl uninstall booted your.bundle.identifier


While it will not reset before each test, it will reset once before the entire suite is run.

  • Wont work if u have migrated to TestPlans and have multiple testplans esp one with Unit Tests

Add a Comment

I was wondering if anyone came up with a solution for this?

I'm using this to reset the application content and settings on the tear down.

Any updates? I still don't see a resolution to this in Xcode 9.1.

Xcodde 9.2 is in the MAS today...might want to take a look at it.

Any solutions to this yet? Without needing to delete and reinstall the app?