这是我简单的测试用例:
import XCTest @testable import MyApp //it doesn't work
因为这个:
class TabBarControllerTests: XCTestCase { override func setUp() { super.setUp() let defaults = NSUserDefaults.standardUserDefaults() defaults.setObject([],forKey: DBTabBarOrderedIndexesKey) //key is undefined,because of lack of my app module defaults.synchronize() continueAfterFailure = false XCUIApplication().launch() } func testIsOrderOfTabsSaved() { XCUIApplication().tabBars.buttons["Catering"].tap() //what next? } }
一旦我点击UITabBarItem我更改了DBAppSettings.mode的值,所以这里我想访问我的DBAppSettings.mode属性来检查它是否真的改变了.
我注意到有一个奇怪的事情,当我构建我的应用程序,并检查是什么构建,没有为我的UITest目标的构建.是不是重要?
解决方法
这是苹果的回应:
UI tests execute differently from Unit tests – Unit tests run inside your application process so they can access your application code. UI tests execute in a separate process,outside your application,so they can simulate how the user interacts with the application. It’s not expected that you will be able to access your app class from a UI test.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。