Xcode UI测试:如何测试应用程序的首次启动

时间:2015-11-05 12:55:35

标签: ios xcode ui-testing xcode-ui-testing

我正在xCode 7.1中编写UITests,并且有一个在首次启动时测试应用程序的功能。问题是:如何检查应用程序是否首次启动。 我需要这样的东西:

func testFirstLaunching() {
   if ("app is launched for the first time") {
        //test scenario of first launching
     }
   else  {
        //invoke func that will test other scenario
     }
}

有人知道怎么检查这个吗? 应用程序正在使用 NSUserDefaults ,也许Xcode测试有一个超级强大的功能来访问它?

任何建议都很有价值!)

1 个答案:

答案 0 :(得分:0)

以下是您的问题的手动解决方案:

  1. 在您首次展示的ViewController中创建一个全局变量,将其设为false
  2. 在viewDidLoad中,将其值更改为true
  3. 保存
  4. testFirstLaunching()中,阅读变量的值
  5. 使用if语句执行您想做的任何事情
  6. 希望这会有所帮助:)

相关问题