【发布时间】:2014-02-26 22:47:05
【问题描述】:
我在 Play 中有一些 (Scala) 代码,它使用 JPA 进行数据库访问。工作正常。但我想对我的代码进行单元测试,这需要使用模拟 EntityManager。这可能吗?
我的测试是用 specs2 编写的(通过扩展 PlaySpecification)并使用 JUnit 运行。我正在使用 Mockito 来模拟 EntityManager。但我希望能够使用其他框架来做到这一点。
我的代码如下所示:
object MyThing {
def create(...) : MyThing = {
val newThing = ...
JPA.withTransaction(new play.libs.F.Function0[Unit]() {
def apply() = {
JPA.em().persist(newThing)
}
})
return newThing
}
}
如果无法对此代码进行单元测试,是否有其他推荐的数据访问方法?
【问题讨论】:
标签: unit-testing scala playframework playframework-2.2