scalatest中的补丁

scalatest中的补丁,scala,scalatest,monkeypatching,Scala,Scalatest,Monkeypatching,我对scala和scalatest都是新手 我的目标是为以下一小段代码编写一个单元测试: import java.sql.SQLException import com.typesafe.scalalogging.LazyLogging import slick.jdbc.MySQLProfile.api._ import scala.concurrent.{ExecutionContext, ExecutionContextExecutor, Future} object DbCreat

我对scala和scalatest都是新手

我的目标是为以下一小段代码编写一个单元测试:

import java.sql.SQLException

import com.typesafe.scalalogging.LazyLogging
import slick.jdbc.MySQLProfile.api._

import scala.concurrent.{ExecutionContext, ExecutionContextExecutor, Future}

object DbCreator extends LazyLogging {
  implicit val ex: ExecutionContextExecutor = ExecutionContext.global

  def createDatabaseIfNotExist(): Future[String] = {
    Database
      .forURL(url = "some host", user = "user", password = "pass", driver = "driver")
      .run(sqlu"CREATE DATABASE ...").map(_ => "created")
      .recover {
        case e: Throwable => {
          logger.error("Error!", e)
          throw new SQLException(e.getMessage)
        }
      }
  }
}
我以前使用过python,它具有

因此,我的想法是修补导入并在
createDatabaseIfNotExist
中使用的
数据库
类,以便验证不同的场景

不幸的是,我在scalatest中找不到等效/类似的概念

我错过了吗

我的方法错了吗?如果是这样,您建议我如何为
createDatabaseIfNotExist
方法编写UT

当前的
DbCreator
实现是否不够可测试

非常感谢所有的帮助

我看到了几个选项:

  • 或者一些java模拟库
  • JDBC驱动程序(具有scala DSL)