How to run a fresh install of the application every time unit tests are run?
Asked Answered
C

2

16

I've setup some XCTest unit tests for my application and would like every time I run tests for it to run in a brand new install of the application. Currently when I run subsequent tests it runs the tests in the same application that was run before which has a lot of state information already changed by the previous tests.

Is there a way to indicate that when you run unit tests that it should run the tests on a fresh version of your application?

Cocks answered 3/10, 2014 at 19:15 Comment(1)
@SteveRosenberg Clean just cleans your 'build' directory, it doesn't uninstall apps.Cocks
U
31

Maybe this works, but only for Simulator.

In Product > Scheme > Edit Scheme...

enter image description here

xcrun simctl is command line utility to control the iOS Simulator. This uninstalls com.yourcompany.AppName application from booted simulator before running tests.

I don't know how to do like this for real device :(

Unwelcome answered 4/10, 2014 at 7:26 Comment(5)
One could use ios-deploy in the same way perhaps?Visakhapatnam
The way to use this in-between tests is to run it in a yml file or shell within JenkinsSommers
if i want only uninstallation for ui tests how can i do that? i dont want in unit tests.Mutualize
@LaserHawk could you elaborate more? Perhaps in a separate answer?Agiotage
This still does not work for device.Dichogamy
L
10

In addition to @rintaro's answer, if you set "Provide build settings from" to your app, you can add a generic command, which will keep working when your bundle id changes:

xcrun simctl uninstall booted ${PRODUCT_BUNDLE_IDENTIFIER}
Lanettelaney answered 8/2, 2016 at 13:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.