相关疑难解决方法(0)

如何让应用知道它的运行单元是否在纯Swift项目中测试?

在XCode 6.1中运行测试时,一个令人讨厌的事情是整个应用程序必须运行并启动其storyboard和root viewController.在我的应用程序中,它运行一些获取API数据的服务器调用.但是,我不希望应用程序在运行其测试时执行此操作.

随着预处理器宏的消失,对于我的项目来说最好的是要知道它是在运行测试而不是普通的启动时启动的吗?我用CMD + U和机器人正常运行它们.

伪代码将是:

// Appdelegate.swift

if runningTests() {
   return
} else {
   // do ordinary api calls
}
Run Code Online (Sandbox Code Playgroud)

xcode ios xctest swift

68
推荐指数
11
解决办法
2万
查看次数

从XCTestCase访问项目代码 - UI测试

我正在尝试在我的项目中设置UI测试.我正在进行UI测试,试图通过我的应用程序登录提示登录.为了确保在测试启动时显示登录提示,我正在尝试运行ServerManager.logout(),这是在项目的代码库中.这将导致在启动时显示登录提示.

import XCTest

class SmokeTest: XCTestCase {

    override func setUp() {
        super.setUp()

        // Put setup code here. This method is called before the invocation of each test method in the class.

        // In UI tests it is usually best to stop immediately when a failure occurs.
        continueAfterFailure = false
        // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
        XCUIApplication().launch()

        // In UI tests it’s …
Run Code Online (Sandbox Code Playgroud)

xcode ios xctest xcode-ui-testing

7
推荐指数
1
解决办法
2771
查看次数

标签 统计

ios ×2

xcode ×2

xctest ×2

swift ×1

xcode-ui-testing ×1