我尝试在我的应用程序中使用 Scalamock 模拟,但我想模拟的是一个带有参数的类。我看到了 scalamock 文档,他们说要模拟类,我必须导入org.scalamock.annotation.mock
才能使用某些功能。我的参考是 scalatest docs。
“注释”似乎不存在......
我的 sbt 依赖项:
"org.scalamock" % "scalamock-scalatest-support_2.10" % "3.0.1" % "test"
"org.scalamock" % "scalamock-core_2.10" % "3.0.1"
我想我忘记了一个图书馆,但我不知道它是什么..
编辑 :
测试代码:
import org.scalatest.FlatSpec
import org.scalamock.scalatest.MockFactory
class AuthenticationServiceTest extends FlatSpec with MockFactory
{
"A user" should " be authenticated" in
{
val user = mock[User]
val tenant = mock[Tenant]
inSequence {
(authenticate(tenant, user) _).expects.returning(true)
}
assert(authenticate(tenant, user))
}
}
课程:
class User (
val username : String,
var password : String,
var firstname : String,
var lastname : String,
var isActivated : Boolean,
val tenantId : TenantId
)
{}
class Tenant (
val tenantId : TenantId,
val companyName : String,
var fullAddress : String,
var email : String,
var phone : String,
var isActivated : Boolean
)
{}
测试方法:
def authenticate(tenant: Tenant, user: User): Boolean = {
//code...
}
错误 :
[error] Unspecified value parameters username, password, firstname, ...
[error] val user = mock[User]
[error] ^
[error] one error found
[error] (test:compile) Compilation failed
[error] Total time: 9 s, completed 17 oct. 2013 09:16:18