【发布时间】:2014-06-23 08:31:00
【问题描述】:
我有以下 specs2 测试:
package concurrent
import akka.actor.{Props, actorRef2Scala}
import akka.testkit.TestActorRef
import scala.concurrent.duration._
class MessageCoordinatingActorSpec extends ActorBaseSpec {
"MessageCoordinatingActor" should {
"receive a Result and update the related token and status" in {
val (repositoryActorProbe, messageCoordinatingActorRef) = buildMockMessageCoordinatingActor
val addresses = MockSession.getTestAddressesWithServicesAt(
"16 Main Street", List("Service1", "Service2"))
val postCode = Postcode("NE28 9QR", addresses)
val matchedAddr = addresses.find(_.addrToken=="16 Main Street")
messageCoordinatingActorRef ! Result(LookupResult(
LookupStatus.ServicesAvailable, postCode, matchedAddr, true), testRecord)
//Expect message to persist the virgin postcode record
repositoryActorProbe.expectMsg(pairLongToDuration(3, SECONDS),
PersistPostcode(postCode))
1 mustEqual 1
}
}
}
abstract class ActorBaseSpec extends TestKit(ActorSystem("test")) with ImplicitSender with MustMatchers with SpecificationLike with Mockito {
//This class just contains some fixture factory methods
//such as buildMockMessageCoordinatingActor
}
测试的内容对我的问题并不重要,但我有两个问题。首先注意我必须使用
pairLongToDuration(3, SECONDS)
我希望能够使用
3.seconds (from the scala.concurrent.duration package)
但是当我这样做时,我收到以下错误:
[error] found : org.specs2.time.Duration
[error] required: scala.concurrent.duration.FiniteDuration
知道如何解决这个问题吗?
还要注意我必须坚持
1 mustEqual 1
在底部。如果我把这个拿出来,我会得到
[error] /Users/.../MessageCoordinatingActorSpec.scala:18: could not find implicit value for evidence parameter of type org.specs2.execute.AsResult[concurrent.RepositoryActor.UpdateAddrToken]
specs2 似乎没有将probe.expectMsg 成功识别为测试成功,有什么方法可以更令人满意地解决这个问题吗?
干杯! NFV
【问题讨论】: