运行 在 Kitura 中进行单元测试时出错
Errors when running unit tests in Kitura
我是 Kitura 和 Xcode 的新手,在添加测试文件时遇到了一些问题。
它似乎与@testing 指令有关。
我的设置与 Kitura website 上显示的相同。
当我在控制台中调用 swift build 然后 swift test 我得到以下错误:
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 package generate-xcodeproj)测试它时,我得到编译错误:
没有测试文件,一切正常。
下面我介绍项目结构:
我认为问题是 Swift 无法为包含 main.swift
文件的模块编译单元测试(即,要编译成可执行文件而不是库的模块用于其他项目)。我克隆了你的 repo,并且在 1) 删除 main.swift
和 2) 取消注释可测试的导入语句后能够编译和 运行 单元测试。
我是 Kitura 和 Xcode 的新手,在添加测试文件时遇到了一些问题。 它似乎与@testing 指令有关。 我的设置与 Kitura website 上显示的相同。 当我在控制台中调用 swift build 然后 swift test 我得到以下错误:
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 package generate-xcodeproj)测试它时,我得到编译错误:
没有测试文件,一切正常。 下面我介绍项目结构:
我认为问题是 Swift 无法为包含 main.swift
文件的模块编译单元测试(即,要编译成可执行文件而不是库的模块用于其他项目)。我克隆了你的 repo,并且在 1) 删除 main.swift
和 2) 取消注释可测试的导入语句后能够编译和 运行 单元测试。