【问题标题】:gradle test for akka with testkit使用 testkit 对 akka 进行 gradle 测试
【发布时间】:2018-08-13 15:29:55
【问题描述】:

我有一个 Scala + Akka + Gradle 应用程序和以下测试:

class UserCRUDSpec() extends TestKit(ActorSystem("UserCRUDSpec"))
  with ImplicitSender
  with WordSpecLike
  with Matchers
  with Mockito
  with DomainSuit {

  val userDao: UserDao = mock[UserDao]
  val actor: ActorRef = system.actorOf(UserCRUD.props(self, userDao))

  "The UserCRUD actor " must {

    "search actor by id if actorId specified and exists" in {
       ...
    }

  }

}

还有一个 gradle build.gradle 依赖:

    apply plugin: 'scala'

    dependencies {
        compile 'org.scala-lang:scala-compiler:2.12.6'
        compile('com.typesafe.akka:akka-cluster_2.12:2.5.14') {
            exclude group: 'org.scala-lang'
        }
        testCompile ('com.typesafe.akka:akka-testkit_2.12:2.5.14') {
            exclude group: 'org.scala-lang'
        }
        testCompile ('org.scalatest:scalatest_2.12:3.0.5') {
            exclude group: 'org.scala-lang'
        }
        testCompile ('org.specs2:specs2-core_2.12:4.3.3') {
            exclude group: 'org.scala-lang'
        }
        testCompile ('org.specs2:specs2-mock_2.12:4.3.3') {
            exclude group: 'org.scala-lang'
        }
    }
}

当我运行./gradle test 时,它说没有找到任何测试。有什么办法可以添加 TestKit 测试以对 gradle test 任务可见?

【问题讨论】:

    标签: scala gradle akka akka-testkit


    【解决方案1】:

    最后,我只是切换到了scalatest和指定的actor系统:

    class UserCRUDSpec() extends WordSpec with TestKitBase ... {
      ...
      implicit lazy val system: ActorSystem = ActorSystem("UserCRUDSpec")
      ...
    }
    

    【讨论】:

      猜你喜欢
      • 2015-10-25
      • 2018-05-08
      • 2017-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多