我有一个最后的课程:
public final class AClass {
private final AConfig aClassConfig;
public final static BeanName = "aClass"
}
我试图在测试中嘲笑它:
@RunWith(classOf[PowerMockRunner])
@PrepareForTest(Array(classOf[AClass]))
class AClassTests extends FunSuite {
test("mock final class test") {
val aClass = PowerMockito.mock(classOf[AClass])
assert(aClass != null)
}
}
这会导致错误:
Cannot subclass final class class com.me.AClass
java.lang.IllegalArgumentException: Cannot subclass final class class com.me.AClass
我已经关注了如何设置这些测试的多个教程,据我所知,错误是由于@PrepareForTest(...)运行不正常,但这只是猜测。