I have a spring boot project that needs to test with spring test runner(so that I can get the real application context) and mock the static method.
@RunWith(
I found a fix from here link to use PowerMockRunnerDelegate instead of PowerMockRule.
The updated test class would be:
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes= MyApplication.class)
@PrepareForTest(StaticClass.class)
public class StaticClassTest {
@Autowired
HelloCmd hello;
@Test
public void testGetOne() {
mockStatic(StaticClass.class);
when(StaticClass.getNumber()).thenReturn(2);
System.out.println(hello.getNumber());
}
}