我对使用 sbt 运行的 spec2 消费者的 Pact JVM 有问题。- 有什么问题?- 我不生成任何协议文件。
给定:
具有依赖项的 sbt 项目
“au.com.dius”%%“pact-jvm-consumer-specs2”%“3.2.11”
“org.specs2” %% “specs2-junit” % “3.3.1”
我有规格类:
import java.util.concurrent.TimeUnit.MILLISECONDS
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.HttpRequest
import akka.stream.ActorMaterializer
import au.com.dius.pact.consumer.PactSpec
import org.junit.runner.RunWith
import org.specs2.mutable.Specification
import org.specs2.runner.JUnitRunner
import scala.concurrent.duration._
import scala.concurrent.Await
import scala.concurrent.duration.Duration
@RunWith(classOf[JUnitRunner])
class PactClientSpec extends Specification with PactSpec {
sequential
override val provider: String = "SpecsProvider"
override val consumer: String = "SpecsConsumer"
implicit val actorSystem = ActorSystem()
implicit val materializer = ActorMaterializer()
implicit val dispatcher = actorSystem.dispatcher
val timeout = Duration(5000, MILLISECONDS)
override def is = uponReceiving("a request for foo")
.matching(path = "/users/1234")
.willRespondWith(body = "{}")
.withConsumerTest { providerConfig =>
val responseFuture= Http().singleRequest(HttpRequest(uri = s"http://${providerConfig.url}/users/1234"))
val response = Await.result(responseFuture, 10 seconds)
"Hello world" must endWith("world")
}
}
当我使用 sbt test 运行时,我得到:
x Consumer 'SpecsConsumer' has a pact with Provider 'SpecsProvider': a request for foo 2
[error]
[error] missing:
[error] method: GET
[error] path: /users/1234
[error] query: null
[error] headers: [:]
[error] matchers: [:]
[error] body: au.com.dius.pact.model.OptionalBody(EMPTY, ) (PactSpec.scala:29)
[info] PactClientSpec
[info]
[info] Total for specification PactClientSpec
[info] Finished in 707 ms
[info] 1 example, 1 failure, 0 error
[info]
[info] ScalaCheck
[info] Passed: Total 0, Failed 0, Errors 0, Passed 0
[info] ScalaTest
[info] Run completed in 2 seconds, 562 milliseconds.
[info] Total number of tests run: 0
[info] Suites: completed 0, aborted 0
[info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] No tests were executed.
[error] Failed: Total 1, Failed 1, Errors 0, Passed 0
[error] Failed tests:
[error] PactClientSpec
[error] (token-manager/test:testOnly) sbt.TestsFailedException: Tests unsuccessful
[error] Total time: 8 s, completed Sep 29, 2016 2:26:52 PM