Scala / PowerMockito - 使用Powermockito在Scala测试中导致构建错误的Java final类

时间:2015-12-29 17:16:21

标签: mockito final powermockito

我有一个最后的课程:

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(...)运行不正常,但这只是猜测。

0 个答案:

没有答案