简体   繁体   English

如何在Scala Slick中模拟数据库

[英]How to mock db in Scala Slick

I am trying to mock db in a "Service" layer that is using Slick in order to Unit Test action composition in it. 我试图在使用Slick的“服务”层中模拟数据库,以便在其中单元测试操作组合。

Unfortunately I am not able to mock the db and JdbcProfile with Mockito. 不幸的是我不能嘲笑db和JdbcProfile用的Mockito。 In particular I am not able to mock JdbcProfile#API in these lines of code: 特别是我无法在这些代码行中模拟JdbcProfile#API

  import driver.api._

  val dbConfig = databaseConfigProvider.get[JdbcProfile]

Do you know a better strategy to unit test Slick (I don't want to use Acolyte )? 你知道一个更好的策略来单元测试Slick(我不想使用Acolyte )吗?

have you considered mocking at a lower level? 你考虑过较低级别的嘲笑吗?

personally I have a wrapper method that encapsulates the Database.forDataSource call. 我个人有一个封装Database.forDataSource调用的包装器方法。 In my tests I spy that method to return a mock[Database] which I can use for all my persistence layer tests. 在我的测试中,我监视该方法返回一个模拟[数据库],我可以用于所有的持久层测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM