Mock java.lang.Runtime with PowerMockito
问题 want to write an unittest for a method like public static void startProgram() { process = Runtime.getRuntime().exec(command, null, file); } I don't want to inject the runtime object for some reasons, so I wanted to stub the getRuntime method that it returns a Runtime mock... I tried it this way: @RunWith(PowerMockRunner.class) @PrepareForTest(Runtime.class) public class ProgramTest { @Test public void testStartProgram() { Runtime mockedRuntime = PowerMockito.mock(Runtime.class); PowerMockito