使用specs2with scalikejdbc 2.4.1运行单元测试时遇到问题,scalikejdbc-config2.4.1 这是我的代码:
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发现了数据库的配置,但它无法初始化连接池。 你有什么主意吗?感谢。
答案 0 :(得分:1)
DBs.closeAll()
在运行测试之前关闭连接池。