Mockito ไม่สามารถจับวิธีคงที่ แต่เนื่องจากMockito 2.14.0คุณสามารถจำลองได้โดยการสร้างอินสแตนซ์การเรียกใช้ของวิธีการคงที่
ตัวอย่าง (สกัดจากการทดสอบ ):
public class StaticMockingExperimentTest extends TestBase {
    Foo mock = Mockito.mock(Foo.class);
    MockHandler handler = Mockito.mockingDetails(mock).getMockHandler();
    Method staticMethod;
    InvocationFactory.RealMethodBehavior realMethod = new InvocationFactory.RealMethodBehavior() {
        @Override
        public Object call() throws Throwable {
            return null;
        }
    };
    @Before
    public void before() throws Throwable {
        staticMethod = Foo.class.getDeclaredMethod("staticMethod", String.class);
    }
    @Test
    public void verify_static_method() throws Throwable {
        //register staticMethod call on mock
        Invocation invocation = Mockito.framework().getInvocationFactory().createInvocation(mock, withSettings().build(Foo.class), staticMethod, realMethod,
                "some arg");
        handler.handle(invocation);
        //verify staticMethod on mock
        //Mockito cannot capture static methods so we will simulate this scenario in 3 steps:
        //1. Call standard 'verify' method. Internally, it will add verificationMode to the thread local state.
        //  Effectively, we indicate to Mockito that right now we are about to verify a method call on this mock.
        verify(mock);
        //2. Create the invocation instance using the new public API
        //  Mockito cannot capture static methods but we can create an invocation instance of that static invocation
        Invocation verification = Mockito.framework().getInvocationFactory().createInvocation(mock, withSettings().build(Foo.class), staticMethod, realMethod,
                "some arg");
        //3. Make Mockito handle the static method invocation
        //  Mockito will find verification mode in thread local state and will try verify the invocation
        handler.handle(verification);
        //verify zero times, method with different argument
        verify(mock, times(0));
        Invocation differentArg = Mockito.framework().getInvocationFactory().createInvocation(mock, withSettings().build(Foo.class), staticMethod, realMethod,
                "different arg");
        handler.handle(differentArg);
    }
    @Test
    public void stubbing_static_method() throws Throwable {
        //register staticMethod call on mock
        Invocation invocation = Mockito.framework().getInvocationFactory().createInvocation(mock, withSettings().build(Foo.class), staticMethod, realMethod,
                "foo");
        handler.handle(invocation);
        //register stubbing
        when(null).thenReturn("hey");
        //validate stubbed return value
        assertEquals("hey", handler.handle(invocation));
        assertEquals("hey", handler.handle(invocation));
        //default null value is returned if invoked with different argument
        Invocation differentArg = Mockito.framework().getInvocationFactory().createInvocation(mock, withSettings().build(Foo.class), staticMethod, realMethod,
                "different arg");
        assertEquals(null, handler.handle(differentArg));
    }
    static class Foo {
        private final String arg;
        public Foo(String arg) {
            this.arg = arg;
        }
        public static String staticMethod(String arg) {
            return "";
        }
        @Override
        public String toString() {
            return "foo:" + arg;
        }
    }
}
เป้าหมายของพวกเขาคือไม่สนับสนุนการเยาะเย้ยโดยตรง แต่เพื่อปรับปรุง API สาธารณะเพื่อให้ไลบรารี่อื่น ๆ เช่นPowermockitoไม่จำเป็นต้องพึ่งพา API ภายในหรือต้องทำซ้ำโค้ด Mockito โดยตรง (ที่มา )
  คำเตือน: ทีม Mockito คิดว่าถนนสู่นรกเต็มไปด้วยวิธีการคงที่ อย่างไรก็ตามงานของ Mockito ไม่ได้เป็นการป้องกันรหัสของคุณจากวิธีการคงที่ หากคุณไม่ต้องการให้ทีมของคุณทำการเยาะเย้ยแบบคงที่ให้หยุดใช้ Powermockito ในองค์กรของคุณ Mockito จำเป็นต้องพัฒนาเป็นชุดเครื่องมือที่มีวิสัยทัศน์ที่มีความคิดเห็นเกี่ยวกับวิธีการทดสอบ Java ที่ควรเขียน อย่างไรก็ตาม Mockito ไม่เชื่อฟัง เราไม่ต้องการปิดกั้นกรณีการใช้ที่ไม่ได้รับการแนะนำเช่นการเยาะเย้ยแบบคงที่ มันไม่ใช่งานของเรา