如何将我的App模块导入MyAppUITests文件? [英] How to import my App module into MyAppUITests file?
问题描述
这是我的简单测试用例:
This is my simple test case:
import XCTest
@testable import MyApp //it doesn't work
因为:
< a href =https://i.stack.imgur.com/4sLjS.png =nofollow noreferrer>
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
属性,用于检查是否真的发生了变化。
Once I tap UITabBarItem
I change the value of DBAppSettings.mode
, so here I would like to have an access to my DBAppSettings.mode
property to check if it is really changed.
我注意到有一个奇怪的事情,当我构建我的应用程序并检查构建的内容时,不是我的UITest目标的构建。这很重要吗?
I noticed that there is one weird thing, when I build my app, and check what was built, there is no build for my UITest target. Is it important?
推荐答案
这是来自Apple的回复:
This is a response from Apple:
UI测试与单元测试的执行方式不同 - 单元测试在应用程序进程内运行所以他们可以访问您的应用程序代码UI测试在应用程序外部的单独进程中执行,因此可以模拟用户与应用程序交互的方式。预计您无法通过UI测试访问您的应用类。
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.
这篇关于如何将我的App模块导入MyAppUITests文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!