Can PowerMock instantiate an inner class for test cases?

后端 未结 2 1846
暗喜
暗喜 2021-02-20 09:34

I\'m attempting to test a class with a number of private classes (yes, I know this is generally considered poor practice for testability, but this question is not in regards to

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-20 09:53

    You can mock it like this:

    InnerClassType innerClass = (InnerClassType) Mockito.mock(
        Class.forName(EnclosingClass.class.getName() + "$InnerClass")
    );
    

提交回复
热议问题