这个问题似乎很明显,我知道,但是我已经尝试了在文档上编写的所有东西,我不能在任何类上模拟一个方法。
在这个测试中,我将scalaMock 3用于Scala2.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
}DateService.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: ? ⇒ ?我在这里做错什么了吗?还有其他方法来设定方法的期望吗?
发布于 2015-10-27 17:13:59
getDate方法需要一个SQLContext -尝试添加一个)或传递特定的sqlc
(m.getDate _).expects(*).returning(Some(new DateTime))
// Or, alternatively
(m.getDate _).expects(sqlc).returning(Some(new DateTime))https://stackoverflow.com/questions/33365400
复制相似问题