title: Scala - write unit tests for objects/singletons that extends a trait/class with DB connection
body: <p>Unit test related question</p>
  
  <p>Encountered a problem with testing scala objects that extend another trait/class that has a DB connection (or any other "external" call)</p>
  
  <p>Using a singleton with a DB connection anywhere in my project makes unit-test not be a option because I cannot override / mock the DB connection</p>
  
  <p>This results in changing my design only for test purpose in situations where its clearly needed to be a object</p>
  
  <p>Any suggestions ? </p>
  
  <p>Code snippet for a non testable code :</p>
  
  <pre><code>object How2TestThis extends SomeDBconnection {
  
    val somethingUsingDB = {
      getStuff.map(//some logic)
    }
  
    val moreThigs {
      //more things
    }
  
  }
  
  trait SomeDBconnection {
    import DBstuff._
    val db = connection(someDB)  
    val getStuff = db.getThings
  }
  </code></pre>