ios – 如何将我的App模块导入MyAppUITests文件?

前端之家收集整理的这篇文章主要介绍了ios – 如何将我的App模块导入MyAppUITests文件?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我简单的测试用例:
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.

原文链接:https://www.f2er.com/iOS/336597.html

猜你在找的iOS相关文章