Can implicit value be also a lazy value when used as implicit method parameter value?

Viewed 628

I have a test suite which uses Slick for DB access. Some tests in this suite access the DB and some not. My suite has

implicit val db = DB.getDB

which effectively initializes DataBaseDef at the beginning of the suite execution. This value then is used as implicit parameter value for some methods. Also it has the afterAll() which closes the db at the end of suite execution:

override def afterAll():Unit={
    db.close()
    super.afterAll()
  }

Now if I changed to: implicit lazy val db = DB.getDB then what exactly will happen?

If I run only a test which does not use the DB then the connection will not be initialized and in the afterAll() it will still try to close the connection and I have a problem in this case, right? I tried to run but no error happened and no exception was thrown...

My knowledge of implicits is not enough to help me understand it in combination with lazy.

2 Answers
Related