1

この質問は私が知っていることは明らかですが、ドキュメントに書かれていることはすべて試しましたが、どのクラスでも単一のメソッドをモックすることはできません。

このテストでは、Scala 2.10 および ScalaTest 2 用の scalaMock 3 を使用しています。

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: ? ⇒ ?

ここで何か間違ったことをしていますか?メソッドの期待値を設定する別の方法はありますか?

4

1 に答える 1

0

あなたのgetDateメソッドは a を期待しています-ワイルドカード ( )SQLContextを追加するか、特定の を渡します:*sqlc

(m.getDate _).expects(*).returning(Some(new DateTime))
// Or, alternatively
(m.getDate _).expects(sqlc).returning(Some(new DateTime))
于 2015-10-27T17:13:59.663 に答える