首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >specs2 --无法创建实例

specs2 --无法创建实例
EN

Stack Overflow用户
提问于 2014-02-17 13:34:09
回答 2查看 4.1K关注 0票数 7
代码语言:javascript
复制
testOnly play.api.weibo.StatusesShowBatchSpec
[error] Could not create an instance of play.api.weibo.StatusesShowBatchSpec
[error]   caused by java.lang.Exception: Could not instantiate class play.api.weibo.StatusesShowBatchSpec: null
[error]   org.specs2.reflect.Classes$class.tryToCreateObjectEither(Classes.scala:93)
[error]   org.specs2.reflect.Classes$.tryToCreateObjectEither(Classes.scala:211)
[error]   org.specs2.specification.SpecificationStructure$$anonfun$createSpecificationEither$2.apply(BaseSpecification.scala:119)
[error]   org.specs2.specification.SpecificationStructure$$anonfun$createSpecificationEither$2.apply(BaseSpecification.scala:119)
...

规格

代码语言:javascript
复制
package play.api.weibo

import org.junit.runner.RunWith
import org.specs2.runner.JUnitRunner

class StatusesShowBatchSpec extends ApiSpec {

  "'statuses show batch' api" should {
    "read statuses" in {
      val api = StatusesShowBatch(
        accessToken = testAdvancedToken,
        ids = "3677163356078857")
      val res = awaitApi(api)
      res.statuses must have size (1)
    }

}}

参见这里的完整代码错误

全堆栈跟踪https://gist.github.com/jilen/9050548

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-02-18 02:37:39

ApiSpec类中,有一些变量在实例化时可能为null:

代码语言:javascript
复制
val cfg = ConfigFactory.load("http.conf")
val testToken = cfg.getString("token.normal")
val testAdvancedToken = cfg.getString("token.advanced")

implicit val http = new SprayHttp {
  val config = new SprayHttpConfig {
    val system = ActorSystem("test")
    val gzipEnable = true
  }
  val context = config.system.dispatcher
}

为了避免这种情况,您可以将这些值转换为懒惰的值:

代码语言:javascript
复制
lazy val cfg = ConfigFactory.load("http.conf")
lazy val testToken = cfg.getString("token.normal")
lazy val testAdvancedToken = cfg.getString("token.advanced")

implicit lazy val http = new SprayHttp {
  lazy val config = new SprayHttpConfig {
    val system = ActorSystem("test")
    val gzipEnable = true
  }
  val context = config.system.dispatcher
}
票数 6
EN

Stack Overflow用户

发布于 2014-07-15 17:43:30

我在使用specs2版本2.3.10关于Scala 2.10时遇到了一个非常类似的错误。升级到2.3.13会使错误消息提供更多的信息,并为根本原因提供额外的堆栈跟踪。这个更新的版本是最近发布的(在这篇文章发布前8天),所以希望你能够适应一个更新.

我的一些问题最终与接受的答案中的vallazy val问题有关;然而,除了调试其他初始化问题之外,我现在还能够准确地指出这些错误发生在哪一行上。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21830495

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档