Powermock mockstatic Cannot subclass final class

前端 未结 3 2028
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-18 23:12

I am trying to mock a final class

PowerMockito.mockStatic(TestFinalClass.class);

It is working from my eclipse when I run a single junit and ad

3条回答
  •  走了就别回头了
    2021-02-18 23:54

    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.powermock.api.mockito.PowerMockito;
    import org.powermock.core.classloader.annotations.PrepareForTest;
    import org.powermock.modules.junit4.PowerMockRunner;
    
    @RunWith(PowerMockRunner.class)
    @PrepareForTest(FinalClass.class)
    public class TestFinalClass{
    
        @Test
        public void whenMockFinalClassMockWorks() {
    
            FinalClass finalklass = PowerMockito.mock(FinalClass.class);
        }
    }
    

提交回复
热议问题