在Kitura中运行单元测试时出错

时间:2017-02-07 22:25:01

标签: swift xcode kitura

我是Kitura和Xcode的新手,在添加测试文件时遇到了一些问题。 它似乎与@testing指令有关。 我的设置与Kitura website上显示的相同。 当我在控制台中调用 swift build 然后快速测试时,我收到以下错误:

Compile Swift Module 'testTests' (1 sources)
Linking ./.build/debug/testPackageTests.xctest/Contents/MacOS/testPackageTests
Undefined symbols for architecture x86_64:
  "__TFC4test3OkoCfT_S0_", referenced from:
      __TFC9testTests8OkoTests8test_addfT_T_ in OkoTests.swift.o
  "__TMaC4test3Oko", referenced from:
      __TFC9testTests8OkoTests8test_addfT_T_ in OkoTests.swift.o
ld: symbol(s) not found for architecture x86_64
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/*user*/Projects/Kitura/test/.build/debug.yaml test

但是当我注释掉 @testable import test 并输入 swift build 然后 swift test 时,我会收到以下错误:

Compile Swift Module 'testTests' (1 sources)
/Users/*user*/Projects/Kitura/test/Tests/testTests/OkoTests.swift:6:17: error: use of unresolved identifier 'Oko'
        let o = Oko()
                ^~~
<unknown>:0: warning: 'cacheParamsComputed' is deprecated
<unknown>:0: warning: 'cacheAlphaComputed' is deprecated
<unknown>:0: warning: 'keepCacheWindow' is deprecated
<unknown>:0: error: 'memoryless' is unavailable
Metal.MTLCommandBufferError:19:14: note: 'memoryless' has been explicitly marked unavailable here
        case memoryless
             ^
<unknown>:0: error: build had 1 command failures
error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/*user*/Projects/Kitura/test/.build/debug.yaml test

当我尝试从Xcode生成的项目中测试它时( swift包generate-xcodeproj )然后我得到编译错误:

Xcode build error

没有测试文件,一切正常。 下面我介绍项目结构:

Xcode Project structure

1 个答案:

答案 0 :(得分:3)

我认为问题是Swift无法为包含main.swift文件的模块编译单元测试(即,要编译为可执行文件的模块,而不是用于其他项目的库) 。我克隆了你的repo,并且能够在1)删除main.swift和2)取消注释testable import语句之后编译并运行单元测试。

相关问题