【发布时间】:2015-04-19 18:41:21
【问题描述】:
我必须测试包含私有 val 的 trait,但是这个 val 需要被覆盖以测试提议。
trait A {
private val someVariable = 0
}
测试类
@RunWith(classOf[JUnitRunner]) class ATest extends FunSuite {
val a = new A{
override private val someVariable = 1
}
test("test of someVariable ){
assert(a.someVariable == 1) //I know that I can't print private variable in this way, but it is just for showing what I need.
}
}
这里有什么方法可以覆盖这个变量吗? 谢谢
【问题讨论】:
-
为什么不定义为
protected? -
我无法更改封装。
标签: scala