Miranda
Miranda

Reputation: 129

how to unit test uploading happens when the app is running in the background

I want to write a unit test function, which aims at testing uploading happens when the app is running in the background. It is generally like this:

func checkBackgroundUploading() {
   set the UIState to be background
   write a record and upload it to database in this UIState
}

I know how to do the second step, but how to set the UIState to be background?

Upvotes: 0

Views: 917

Answers (1)

FromTheStix
FromTheStix

Reputation: 429

I have had success in testing sounds in the background by using this solution, that I found on SO. The gist of it is to send the app to the background by programmatically pressing the home button. Hope it helps.

    XCUIDevice().pressButton(XCUIDeviceButton.Home)

Upvotes: 1

Related Questions