我无法在我的Vapor应用程序中进行测试。看起来链接器似乎没有找到任何正在测试的应用程序类。为了缩小问题范围,我尝试使用默认的应用模板创建最简单的测试。步骤如下所示。如果有人能告诉我我做错了什么,或者他们可以复制这个问题,我将非常感激。
$ vapor new Foo Cloning Template [Done] $ cd Foo $ mkdir -p Tests/ModelTests
$ 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
这也是我在自己的项目中看到的行为:链接器没有从测试中引用的应用程序中找到类。
已解决,请参阅下面的评论。
答案 0 :(得分:2)
发表评论,但只是让人们看到答案,我也会在这里标记:
SwiftPM对测试强制执行命名约定,因此正确命名为<#YourTarget#>Tests
。
在这种情况下,重命名您的测试模块AppTests
,这应该可以解决问题!