模拟Scala对象的成员

时间:2014-08-06 07:55:50

标签: scala mocking scalatest

package com.project.dir

object A {
  var m = scala.collection.mutable.Map[String, String]()
}

class AB {
  val a = "hello" 
  def function_A(): Unit =  {
    import A._
    // Code that uses member m of A
  }
}

object AB {
  val ab = new AB
  ab.function_A()
}

我正在使用scalatest,在我的测试文件中,我不会导入此软件包,我只是这样做:

val m = mock[com.project.dir.AB]

这允许我访问AB类的成员a和function_A,但我希望能够模拟对象A中的var m

我尝试过:

val m = mock[com.project.dir.A]

但是会返回此错误:

type A is not a member of package com.project.dir.A

在另一个文件中,我导入了com.project.dir.A,我可以调用A.m

0 个答案:

没有答案