在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) 我正在尝试在我的项目中设置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)