Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mock static without @RunWith(PowerMockRunner.class)

I have folowing code:

        @RunWith(PowerMockRunner.class)
        @PrepareForTest({RequestUtils.class, OsgiUtil.class})
        @PowerMockIgnore({"*"})
        public class MyTest
            ...
             @Test
             public somMethod(){    
                ....  
                mockStatic(RequestUtils.class);
                when(RequestUtils.getLocale(request)).thenReturn(locale);
            }
        }  

How to replace this code so that it work without @RunWith(PowerMockRunner.class)?

According the cause described in following link I cannot use @RunWith(PowerMockRunner.class)

like image 913
gstackoverflow Avatar asked Oct 31 '22 22:10

gstackoverflow


1 Answers

Take a look on this discussion: issues while using @RunWith Annotation and powerMock

One of the answers recommends to use PowerMockRule instead of runner. This solution should be good for you.

like image 101
AlexR Avatar answered Nov 09 '22 13:11

AlexR