1

使用带有 scalikejdbc 2.4.1、scalikejdbc-config2.4.1 的 specs2 运行单元测试时出现问题这是我的代码:

    object PostDAOImplSpec extends Specification{

  sequential

  DBs.setupAll
  implicit val session = AutoSession

  "resolveAll shoudn't have any syntax error" in new AutoRollback {

    val postIds = DB readOnly { implicit session =>
      sql"select post_id from posts".map(_.long(1)).list.apply()
    }

  }

  DBs.closeAll()

}

这是日志:

    09:11:16.931 [main] DEBUG scalikejdbc.ConnectionPool$ - Registered connection pool : ConnectionPool(url:jdbc:mysql://localhost/bbs, user:root) using factory : <default>
09:11:17.130 [main] DEBUG scalikejdbc.ConnectionPool$ - Registered connection pool : ConnectionPool(url:jdbc:mysql://localhost/bbs, user:root) using factory : <default>

java.lang.IllegalStateException: Connection pool is not yet initialized.(name:'default)
java.lang.IllegalStateException: Connection pool is not yet initialized.(name:'default)

从前两行可以看出,scalikejdbc 找到了数据库的配置,但是无法初始化连接池。你有什么主意吗?谢谢。

4

1 回答 1

1

DBs.closeAll()运行测试之前关闭连接池。

于 2016-06-04T04:22:55.073 回答