【问题标题】:tests not working in vapor app测试在蒸汽应用程序中不起作用
【发布时间】:2016-11-13 02:10:19
【问题描述】:

我无法在我的 Vapor 应用中进行测试。似乎链接器只是没有找到任何正在测试的应用程序类。为了缩小问题范围,我尝试使用默认应用模板创建最简单的测试。步骤如下所示。如果有人能告诉我我做错了什么,或者他们可以复制这个问题,我将非常感激。

  1. 创建一个新项目。
$ vapor new Foo
Cloning Template [Done]
$ cd Foo
$ mkdir -p Tests/ModelTests
  1. 添加一个引用默认项目中的类的虚拟测试。
$ cat > Tests/ModelTests/PostTests.swift
import XCTest
@testable import App

class PostTests: XCTestCase {
  func testPost() {
    print(Post.self)
    XCTAssertEqual("a", "a")
  }
}
^D
  1. 构建项目。
$ vapor build
No Packages folder, fetch may take a while...
Fetching Dependencies [Done]
Building Project [Done]
  1. 运行测试。
$ vapor test
Testing [Failed]
Log:
swift-test: error: no tests found to execute, create a module in your `Tests' directory
  1. 糟糕,我们似乎需要从 Package.swift 的 exclude: 部分中删除“Tests”。
$ vi Package.swift
   ... remove Tests from exclude: ....
  1. 再试一次。
$ 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
  1. 尝试直接执行如上所示的命令行。
$ /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 强制执行的,尝试将您的测试模块命名为 AppTests 看看是否能解决一些问题。
  • 天哪。我该把你的一瓶世界上最好的威士忌送到哪里?

标签: swift vapor


【解决方案1】:

放入 cmets,但只是为了让人们可以看到答案,我也会在这里标记:

SwiftPM 对测试强制执行命名约定,因此正确的命名应为 &lt;#YourTarget#&gt;Tests

在这种情况下,将您的测试模块重命名为 AppTests 就可以了!

【讨论】:

  • 另外,如果您像我一样是个白痴,请仔细检查您的Package.swift 文件是否没有在exclude 数组中列出Tests
猜你喜欢
  • 2018-01-30
  • 2012-10-21
  • 1970-01-01
  • 2017-07-26
  • 1970-01-01
  • 2019-02-20
  • 1970-01-01
  • 1970-01-01
  • 2020-10-17
相关资源
最近更新 更多