[英]Patches in scalatest
我是 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
导入和使用的Database
类,以便我可以验证不同的场景。
不幸的是,我在 scalatest 中找不到等效/相似的概念。
我错过了吗?
我的方法错了吗? 如果是这样,您如何建议我为createDatabaseIfNotExist
方法编写 UT?
当前的DbCreator
实现是否不够可测试?
非常感谢所有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.