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)
...规格
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)
}}}
参见这里的完整代码错误
发布于 2014-02-18 02:37:39
在ApiSpec类中,有一些变量在实例化时可能为null:
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
}为了避免这种情况,您可以将这些值转换为懒惰的值:
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
}发布于 2014-07-15 17:43:30
我在使用specs2版本2.3.10关于Scala 2.10时遇到了一个非常类似的错误。升级到2.3.13会使错误消息提供更多的信息,并为根本原因提供额外的堆栈跟踪。这个更新的版本是最近发布的(在这篇文章发布前8天),所以希望你能够适应一个更新.
我的一些问题最终与接受的答案中的val和lazy val问题有关;然而,除了调试其他初始化问题之外,我现在还能够准确地指出这些错误发生在哪一行上。
https://stackoverflow.com/questions/21830495
复制相似问题