测试不能在蒸气应用程序中工作
问题描述:
我一直无法在我的Vapor应用程序中获得测试。好像链接器没有找到任何正在测试的应用程序类。为了缩小问题的范围,我尝试使用默认应用程序模板创建最简单的测试。步骤如下所示。如果任何人都可以告诉我我做错了什么,或者他们可以复制这个问题,我会非常感激。测试不能在蒸气应用程序中工作
- 创建一个新项目。
$ vapor new Foo Cloning Template [Done] $ cd Foo $ mkdir -p Tests/ModelTests
- 添加伪测试,在默认项目引用的类。
- 生成项目。
- 运行测试。
- 糟糕,好像我们需要从排除删除 “测试”:Package.swift的部分。
- 重试。
- 尝试直接执行上面所示的命令行。
$ cat > Tests/ModelTests/PostTests.swift import XCTest @testable import App class PostTests: XCTestCase { func testPost() { print(Post.self) XCTAssertEqual("a", "a") } } ^D
$ vapor build No Packages folder, fetch may take a while... Fetching Dependencies [Done] Building Project [Done]
$ vapor test Testing [Failed] Log: swift-test: error: no tests found to execute, create a module in your `Tests' directory
$ vi Package.swift ... remove Tests from exclude: ....
$ vapor test Testing [Failed] Log: <unknown>:0: error: build had 1 command failures swift-test: error: exit(1): /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/mark/tmp/Foo/.build/debug.yaml test
$ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-build-tool -f /Users/mark/tmp/Foo/.build/debug.yaml test Linking ./.build/debug/FooPackageTests.xctest/Contents/MacOS/FooPackageTests Undefined symbols for architecture x86_64: "__TMaC3App4Post", referenced from: __TFC10ModelTests9PostTests8testPostfT_T_ in PostTests.swift.o __TMaMC3App4Post in PostTests.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
这是我在自己的项目看,以及行为:链接器不会从测试中引用的应用程序查找类。
已解决,请参阅下面的注释。
答
投入评论,只是让人们可以看到一个答案,我在这里也标志着:
SwiftPM强制对测试的命名约定,所以正确的命名是<#YourTarget#>Tests
。
在这种情况下,请将您的测试模块AppTests
重命名,这应该是个诀窍!
+0
另外,如果你是一个像我这样的白痴,请仔细检查你的'Package.swift'文件没有在'exclude'数组中列出'Tests' – XML
我相信命名测试模块是由SwiftPM强制执行的,试着命名你的测试模块AppTests,看看是否能解决一些问题。 – Logan
我的天啊。我在哪里送你一瓶世界上最好的威士忌? –