sbt: 如何 运行 集成测试

sbt: How to run integration test

根据 documentation:

The standard testing tasks are available, but must be prefixed with it:. For example,

> IntegrationTest / testOnly org.example.AnIntegrationTest

如前所述,我已将此添加到我的 build.sbt:

lazy val server = (project in file("server"))
  .configs(IntegrationTest)

我只想 运行 集成测试。

所以我尝试了不同的方法 - 但 none 奏效了:

[IJ][play-binding-form-server] $ it:test
[error] No such setting/task
[error] it:test
...
[IJ][play-binding-form-server] $ IntegrationTest / testOnly org.example.AnIntegrationTest
[error] Expected whitespace character
[error] Expected '/'
[error] IntegrationTest / testOnly org.example.AnIntegrationTest

如何正确完成?

您需要像这里一样启用settings(Defaults.itSettings)

lazy val server = (project in file("server"))
  .configs(IntegrationTest)
  .settings(Defaults.itSettings)

之后你应该可以在 sbt

中 运行
sbt> it:testOnly test.Spec
sbt> IntegrationTest / testOnly test.Spec

或在sbt之外如

sbt "it:testOnly test.Spec"
sbt "IntegrationTest / testOnly test.Spec"