当应用程序在后台运行时,如何进行单元测试上传

时间:2016-06-09 11:29:43

标签: ios swift unit-testing

我想编写一个单元测试函数,旨在测试上传是在应用程序在后台运行时发生的。通常是这样的:

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

我知道如何进行第二步,但是如何将UIState设置为背景?

1 个答案:

答案 0 :(得分:1)

我使用this solution在后台测试声音已经成功,我在SO上找到了。 它的要点是通过以编程方式按下主页按钮将应用程序发送到后台。希望它有所帮助。

    XCUIDevice().pressButton(XCUIDeviceButton.Home)