Reputation: 732
I am trying to reset the simulator after every test. I found the best way to do it, is to execute
xcrun simctl erase all
but I don't know how to add a shell command in a swift file to execute it.
I tried
import Foundation
func shell(_ args: String...) -> Int32 {
let task = Process()
task.launchPath = "/usr/bin/env"
task.arguments = args
task.launch()
task.waitUntilExit()
return task.terminationStatus
}
But got an error, Process u\identifier not found Please help. I am trying to reset the simulators after each test.
Can I uninstall a particular application from the simulator from the command line? or any other way between each test, in the tearDown()
Upvotes: 0
Views: 544
Reputation: 312
I had a similar issue and was able to resolve it with SBTUITestTunnel. I chose to use this framework as I had also had to communicate between the testing application and my actual application to configure testing states.
With SBTUITestTunnel implemented you can specify launch options, the one you require is SBTUITunneledApplicationLaunchOptionResetFilesystem.
app.launchTunnel(withOptions: [SBTUITunneledApplicationLaunchOptionResetFilesystem]) {
// do additional setup before the app launches
// i.e. prepare stub request, start monitoring requests
}
I would recommend having a look at SBTUITestTunnel as it will allow you to do some other very powerful things.
Upvotes: 3