加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何从命令行为一个swift应用程序运行XCTest?

发布时间:2020-12-14 06:02:04 所属栏目:百科 来源:网络整理
导读:我想使用XCTest从命令行测试驱动器的一些Swift示例,如果可能的话。 import XCTestclass LeapTest : XCTestCase { func testVanillaLeapYear() { let year = Year(calendarYear: 1996) XCTAssertTrue(year.isLeapYear); }} 我想从命令行运行它。 我已经设置X
我想使用XCTest从命令行测试驱动器的一些Swift示例,如果可能的话。
import XCTest

class LeapTest : XCTestCase {

    func testVanillaLeapYear() {
      let year = Year(calendarYear: 1996)
      XCTAssertTrue(year.isLeapYear);
    }
}

我想从命令行运行它。

我已经设置Xcode使用开发工具在测试版:

sudo xcode-select -s /Applications/Xcode6-Beta.app/Contents/Developer/

如果我天真地尝试和运行它就像这样

$ xcrun swift LeapTest.swift
LeapTest.swift:1:8: error: cannot load underlying module for 'XCTest'
import XCTest
       ^

任何方式直接从CLI运行它?还是我必须创建一个Xcode项目?

我能够使用以下命令获取您的XCTestCase编译:
swiftc 
-F/Applications/Xcode6-Beta5.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks 
-Xlinker -rpath -Xlinker /Applications/Xcode6-Beta5.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks 
-lswiftCore LeapTest.swift 
-o LeapTests

然后可以使用xctest执行测试:

xcrun xctest LeapTests

并分解这些swiftc命令行选项:

> -F …添加XCTest.framework到框架搜索路径,使它能从Swift导入
> -Xlinker -rpath …确保在加载时可以找到XCTest共享库
>没有明确指定-lswiftCore,我发现xctest会在试图运行测试套件时崩溃

希望有所帮助!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读