我正在尝试编写一些代码来测试数据库模型。测试框架和数据库框架都使用“===”运算符,并且优先考虑测试框架。如何明确使用一种方法或另一种方法?
例子:
import org.scalatest.FunSuite
class TestDBModels extends FunSuite{
test("Test DoublePropertyEntry with a few new values") {
Schemas.doubleProperties.deleteWhere(p => (p.id === p.id)))
}
}
错误:
type mismatch;
found : Option[String]
required: org.squeryl.dsl.ast.LogicalBoolean
Schemas.doubleProperties.deleteWhere(p => (p.===(p.id, p.id)))
最佳答案
您有多种选择。第一个也是最简单的方法是使用显式方法调用而不是隐式转换。例如,显式使用 scalatest ===:
Schemas.doubleProperties.deleteWhere(p => (convertToEqualizer(p.id) === p.id)))
如果这太长,您可以缩短名称:
def toEq(left: Any) = convertToEqualizer(left: Any)
Schemas.doubleProperties.deleteWhere(p => (toEq(p.id) === p.id)))
convertToEqualizer 是scalatest 的隐式转换方法。另一种选择是将 convertToEqualizer 重写为非隐式方法:
override def convertToEqualizer(left: Any) = new Equalizer(left)
这会阻止这种特定的隐式转换发生。查看scalatest documentation for Assertions object和 same question on the scalatest-users mailing list .
关于Scala 冲突的继承方法名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8079129/