How to mock getResourceAsStream method using PowerMockito and JUnit?
问题 I try to mock getResourceAsStream method which I invoke in constructor. public Conn() { stream = Conn.class.getClass().getResourceAsStream(PATH); } For mock framework I prefer Mockito + PowerMockito. @RunWith(PowerMockRunner.class) @PrepareForTest(Conn.class) public class ConnTest { @Mock private InputStream streamMock; private Conn conn; @Before public void before() { initMocks(this); } @Test public void test() { PowerMockito.mockStatic(Conn.class); PowerMockito.when(Connector.class