首页 > 解决方案 > 用于分离 UITest 代码的 Swift 条件语句

问题描述

IF UItest is running 
{
//execute this code
}
else
{
//execute this code

}

谁能告诉这里的条件语句应该是什么

标签: swiftuitest

解决方案


方法一:通过测试代码传递args

// In UI test file
class ProfileUI: XCTestCase {
    let app = XCUIApplication()

    override func setUpWithError() throws {
        app.launchArguments = ["-isUITestMode", "user_324234"]
        app.launch()
    }
}

方法2:通过scheme传递args

在此处输入图像描述

检查参数

if CommandLine.arguments.contains("-isUITestMode") {
    // running ui test
} else if CommandLine.arguments.contains("-isUnitTestMode") {
    // running unit tests
} else {
    // normal
}

推荐阅读