我知道这个问题似乎很明显,但是我已经尝试了文档上写的所有内容,并且我无法在任何类上模拟单个方法。
对于这个测试,我将 scalaMock 3 用于 Scala 2.10 和 ScalaTest 2
DateServiceTest.scala
@RunWith(classOf[JUnitRunner])
class DateServiceTest extends FunSuite with MockFactory{
val conf = new SparkConf().setAppName("Simple Application").setMaster("local")
val sc = new SparkContext(conf)
implicit val sqlc = new SQLContext(sc)
val m = mock[DateService]
(m.getDate _).expects().returning(Some(new DateTime)) // Error here
}
日期服务.scala
class DateService extends Serializable {
def getDate(implicit sqlc: SQLContext): Option[DateTime] = {
Some(new DateTime(loadDateFromDatabase(sqlc)))
}
}
这对我来说似乎很简单,但期望是向我抛出这个错误
type mismatch; found : Option[org.joda.time.DateTime] required: ? ⇒ ?
我在这里做错了吗?还有另一种方法来设置方法的期望吗?