title: Code coverage on Play! project
body: <p>I have a Play! project where I would like to add some code coverage information. So far I have tried <a href="https://bitbucket.org/jmhofer/jacoco4sbt/wiki/Home" rel="nofollow">JaCoCo</a> and <a href="http://mtkopone.github.com/scct/" rel="nofollow">scct</a>. The former has the problem that it is based on bytecode, hence it seems to give warning about missing tests for methods that are autogenerated by the Scala compiler, such as <code>copy</code> or <code>canEqual</code>. scct seems a better option, but in any case I get many errors during tests with both.</p>
  
  <p>Let me stick with scct. I essentially get errors for every test that tries to connect to the database. Many of my tests load some fixtures into an H2 database in memory and then make some assertions. My <code>Global.scala</code> contains</p>
  
  <pre><code>override def onStart(app: Application) {
      SessionFactory.concreteFactory = Some(() =&gt; connection)
  
      def connection() = {
          Session.create(DB.getConnection()(app), new MySQLInnoDBAdapter)
      }
  }
  </code></pre>
  
  <p>while the tests usually are enclosed in a block like</p>
  
  <pre><code>class MySpec extends Specification {
      def app = FakeApplication(additionalConfiguration = inMemoryDatabase())
  
      "The models" should {
          "be five" in running(app) {
              Fixtures.load()
              MyModels.all.size should be_==(5)
          }
      }
  }
  </code></pre>
  
  <p>The line <code>running(app)</code> allows me to run a test in the context of a working application connected to an in-memory database, at least usually. But when I run code coverage tasks, such as scct <code>coverage:doc</code>, I get a <strong>lot</strong> of errors related to connecting to the database.</p>
  
  <p>What is even more weird is that there are at least 4 different errors, like:</p>
  
  <ul>
  <li>ObjectExistsException: Cache play already exists</li>
  <li>SQLException: Attempting to obtain a connection from a pool that has already been shutdown</li>
  <li>Configuration error [Cannot connect to database [default]]</li>
  <li>No suitable driver found for jdbc:h2:mem:play-test--410454547</li>
  </ul>
  
  <blockquote>
    <p>Why is that launching tests in the default configuration is able to connect to the database, while running in the context of scct (or JaCoCo) fails to initialize the cache and the db?</p>
  </blockquote>