簡體   English   中英

Scalatest 中的補丁

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM